cpp将度分秒形式的经纬度写入图片
时间: 2023-05-18 15:04:43 浏览: 129
可以使用OpenCV库中的putText函数将经纬度信息写入图片中。具体实现可以参考以下代码:
```cpp
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
// 经纬度信息
double longitude = 116.3975;
double latitude = 39.9086;
// 将经纬度转换为度分秒形式
int lon_deg = (int)longitude;
int lon_min = (int)((longitude - lon_deg) * 60);
int lon_sec = (int)(((longitude - lon_deg) * 60 - lon_min) * 60);
int lat_deg = (int)latitude;
int lat_min = (int)((latitude - lat_deg) * 60);
int lat_sec = (int)(((latitude - lat_deg) * 60 - lat_min) * 60);
// 读取图片
Mat img = imread("test.jpg");
// 设置字体和字号
int font_face = FONT_HERSHEY_SIMPLEX;
double font_scale = 0.5;
// 将经纬度信息写入图片
putText(img, "Longitude: " + to_string(lon_deg) + "°" + to_string(lon_min) + "'" + to_string(lon_sec) + "\"", Point(10, 30), font_face, font_scale, Scalar(0, 0, 255), 1);
putText(img, "Latitude: " + to_string(lat_deg) + "°" + to_string(lat_min) + "'" + to_string(lat_sec) + "\"", Point(10, 60), font_face, font_scale, Scalar(0, 0, 255), 1);
// 显示图片
imshow("Image", img);
waitKey(0);
return 0;
}
```
这段代码可以将经纬度信息写入一张名为test.jpg的图片中。你可以根据自己的需求修改图片和字体等参数。
阅读全文
相关推荐














