Skip to content

Commit

Permalink
addressed the linting/format errors
Browse files Browse the repository at this point in the history
  • Loading branch information
miyatakazuya committed Apr 27, 2024
1 parent 7e58721 commit c123253
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
20 changes: 10 additions & 10 deletions include/camera/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
// class to contain all telemetry that should be tagged with an image.
// In the future this could be in a mavlink file.
struct ImageTelemetry {
ImageTelemetry(double latitude, double longitude, double altitude, double airspeed, double heading, double yaw,
double pitch, double roll);
double latitude;
double longitude;
double altitude;
double airspeed;
double heading;
double yaw;
double pitch;
double roll;
ImageTelemetry(double latitude, double longitude, double altitude, double airspeed,
double heading, double yaw, double pitch, double roll);
double latitude;
double longitude;
double altitude;
double airspeed;
double heading;
double yaw;
double pitch;
double roll;
};

/*
Expand Down
8 changes: 5 additions & 3 deletions include/cv/localization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define IMG_WIDTH_PX 5472
#define IMG_HEIGHT_PX 3648
#define EARTH_RADIUS_M 6378137
#define SENSOR_WIDTH 15.86 //mm
#define SENSOR_WIDTH 15.86 // mm
#define METER_TO_FT 3.28084

// Localization is responsible for calculating the real world latitude/longitude
Expand Down Expand Up @@ -90,8 +90,10 @@ class ECEFLocalization : Localization {
class GSDLocalization : Localization {
public:
GPSCoord localize(const ImageTelemetry& telemetry, const Bbox& targetBbox) override;
GPSCoord CalcOffset(const double offset_x, const double offset_y, const double lat, const double lon);
double distanceInMetersBetweenCords(const double lat1, const double lon1, const double lat2, const double lon2);
GPSCoord CalcOffset(const double offset_x, const double offset_y,
const double lat, const double lon);
double distanceInMetersBetweenCords(const double lat1, const double lon1,
const double lat2, const double lon2);
};

#endif // INCLUDE_CV_LOCALIZATION_HPP_
3 changes: 2 additions & 1 deletion src/camera/interface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "camera/interface.hpp"

ImageTelemetry::ImageTelemetry(double latitude, double longitude, double altitude, double airspeed, double heading,
ImageTelemetry::ImageTelemetry(double latitude, double longitude, double altitude,
double airspeed, double heading,
double yaw, double pitch, double roll)
: latitude(latitude),
longitude(longitude),
Expand Down
29 changes: 15 additions & 14 deletions src/cv/localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,33 @@ GPSCoord GSDLocalization::localize(const ImageTelemetry& telemetry, const Bbox&
double img_mid_x = IMG_WIDTH_PX / 2;
double img_mid_y = IMG_HEIGHT_PX / 2;

//midpoints of bounding box around the target
// midpoints of bounding box around the target
double target_x = (targetBbox.x1 + targetBbox.x2)/2;
double target_y = (targetBbox.y1 + targetBbox.y2)/2;

// calculations of bearing
// L = (distance(middle, bbox))*GSD
// L = (distance(middle, bbox))*GSD
double length = (sqrt(pow((target_x - img_mid_x), 2) + pow((target_y - img_mid_y), 2) * GSD));

//Translate Image Cordinates to Camera Cordinate Frame (Origin to Center of Image instead of Top Left)
// Translate Image Cordinates to Camera Cordinate (Origin to Center of Image instead of Top Left) NOLINT
double target_camera_cord_x = target_x - (IMG_WIDTH_PX / 2);
double target_camera_cord_y = (IMG_HEIGHT_PX / 2) - target_y;

//Angle of Bearing (Angle from north to target)
double thetaB = telemetry.heading + atan(target_camera_cord_x / target_camera_cord_y);
// Angle of Bearing (Angle from north to target)
double thetaB = telemetry.heading + atan(target_camera_cord_x / target_camera_cord_y);

//Translate bearing to the 3 quadrant if applicable
if (target_camera_cord_x < 0 && target_camera_cord_y < 0){
// Translate bearing to the 3 quadrant if applicable
if (target_camera_cord_x < 0 && target_camera_cord_y < 0) {
thetaB = 180.0 + thetaB;
}

//Finds the offset of the bbox
double calc_cam_offset_x = target_camera_cord_x * GSD * 0.001; //mm to M
double calc_cam_offset_y = target_camera_cord_y * GSD * 0.001; //mm to M
// Finds the offset of the bbox
double calc_cam_offset_x = target_camera_cord_x * GSD * 0.001; // mm to M
double calc_cam_offset_y = target_camera_cord_y * GSD * 0.001; // mm to M

//Calculates the cordinates using the offset
GPSCoord calc_coord = CalcOffset((calc_cam_offset_x), (calc_cam_offset_y), (telemetry.latitude), (telemetry.longitude));
// Calculates the cordinates using the offset
GPSCoord calc_coord = CalcOffset((calc_cam_offset_x), (calc_cam_offset_y),
(telemetry.latitude), (telemetry.longitude));

return calc_coord;
}
Expand All @@ -173,7 +174,7 @@ Takes the in two cordinaates and outputs their distance in meters.
Reference: http://www.movable-type.co.uk/scripts/latlong.html
*/

double GSDLocalization::distanceInMetersBetweenCords(const double lat1, const double lon1, const double lat2, const double lon2){
double GSDLocalization::distanceInMetersBetweenCords(const double lat1, const double lon1, const double lat2, const double lon2) { // NOLINT
double e1 = lat1 * M_PI / 180;
double e2 = lat2 * M_PI / 180;

Expand All @@ -199,7 +200,7 @@ Takes the position of the camera in blender and the position of the generated ta
@returns true (mostly) world cordinate of target
*/

GPSCoord GSDLocalization::CalcOffset(const double offset_x, const double offset_y, const double lat, const double lon) {
GPSCoord GSDLocalization::CalcOffset(const double offset_x, const double offset_y, const double lat, const double lon) { // NOLINT
double dLat = offset_y / EARTH_RADIUS_M;
double dLon = offset_x / (EARTH_RADIUS_M * cos(M_PI * lat / 180));

Expand Down

0 comments on commit c123253

Please sign in to comment.