1,科学计数法,把小数写成String 1e-X的形式;
double Cells_density9 =0.2;
int ex9 = 0;
while (true) {
ex9++;
Cells_density9 = Cells_density9 * 10;
if (Cells_density9 > 1) {
break;
}
}
int intCells_density9 = Cells_density9 * 100;
Cells_density9 = (double)intCells_density9 / 100;
std::string Cells_density_QSTR9;
Cells_density_QSTR9 = std::to_string(Cells_density9) + "e-" + std::to_string(ex9);
2,opencv倾斜矩形转正的矩形
#include "highgui/highgui.hpp"
#include "imgproc/imgproc.hpp"
#include "iostream"
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
Mat imageSource = imread("D:/testi/QQ图片20200813163358.jpg", 1);
imshow("Source Image", imageSource);
vector<Point> contour;
Point p1(1648, 416), p2(1723, 723), p3(1787, 375), p4(1869, 685);//四个矩形点大概的就可
contour.push_back(p1);
contour.push_back(p2);
contour.push_back(p3);
contour.push_back(p4);
RotatedRect rect = minAreaRect(contour);//外接矩形
Point2f vertices[4];
rect.points(vertices);//外接矩形的4个顶点
for (int i = 0; i < 4; i++)//画矩形
line(imageSource, vertices[i], vertices[(i + 1) % 4], Scalar(255, 0, 0));
/*Rect brect = rect.boundingRect();
rectangle(imageSource, brect, Scalar(255, 0, 0));*/
imshow("Source Image1", imageSource);
Point2f center = rect.center;//外接矩形中心点坐标
Mat rot_mat = getRotationMatrix2D(center, rect.angle, 1.0);//求旋转矩阵
Mat rot_image;
Size dst_sz(imageSource.size());
warpAffine(imageSource, rot_image, rot_mat, dst_sz);//原图像旋转
imshow("rot_image", rot_image);
Mat result1 = rot_image(Rect(center.x - (rect.size.width / 2), center.y - (rect.size.height / 2), rect.size.width, rect.size.height));//提取ROI
imshow("result", result1);
waitKey(0);
return 0;
}
3,保存视频,记得ffmpeg dll放到exe同文件夹下
#include<windows.h>
#include<Shlwapi.h>
#include <opencv2/opencv_modules.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include<string>
#include<vector>
using namespace cv;
using namespace std;
int main()
{
VideoWriter video("C:\\Users\\MLOONG\\Desktop\\yolov4\\darknet-master\\build\\darknet\\x64\\data\\testvideo.mp4", CV_FOURCC('D', 'I', 'V', 'X'), 15.0, Size(1200, 600));
String img_path = "C:\\Users\\MLOONG\\Desktop\\yolov4\\darknet-master\\build\\darknet\\x64\\JPEGImages\\*.jpg";
vector<String> img;
glob(img_path, img, false);
size_t count = img.size();
for (size_t i = 0; i < count; i++)
{
Mat image = imread(img[i]);
resize(image, image, Size(1200, 600));
video << image;
video << image;
video << image;
video << image;
video << image;
cout <<"加入"<< img[i] << endl;
imshow("img", image);
cvWaitKey(1);
}
cout << "处理完毕!" << endl;
}