Thanks for everyone.
Thanks for everyone.
Thanks for everyone.
Please configure according to the instructions in the document. If you can't, you can seek Baidu. There should be methods on the Internet or learn relevant knowledge by yourself
I think you should learn by yourself, I am a newbie in this area too but I can do it on my own.
However, I will give my answer.
1.
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
int main(int argc, char** argv) {
Mat image = imread("E:/1.png");
Mat org1,org2,gray,dst;
Rect rect1(7, 104, 59, 79); // init rect area
Rect rect2(79, 208, 59, 79);//if your draw on your own coumputer desktop,you should at least modify the parameter
Point point(388, 118);
double x1 = 7 + 59 / 2;
double y1 = 104 + 79/ 2;
double x2 = 79 + 59 / 2;
double y2 = 208 + 79 / 2;
double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
cv::rectangle(image, rect1, Scalar(255, 0, 0), 1, LINE_8, 0); //BGR scalar color mode
cv::rectangle(image, rect2, Scalar(0, 255, 0), 1, LINE_8, 0);
org1 = image(rect1); //load area
org2 = image(rect2);
namedWindow("picture1", 0); //use your mouse to drag the window
namedWindow("picture2", 0);
cvtColor(org1, gray, COLOR_BGR2GRAY);//First conver to gray mode
threshold(gray, dst, 0, 255, THRESH_BINARY);//Then binary it;
putText(image, "Distance:"+std::to_string(distance), point, FONT_HERSHEY_SIMPLEX, 1, CV_RGB(255, 0, 0), 2); //draw text
imshow("test", image);
imshow("picture1", dst);
imshow("picture2", org2);
waitKey(0);
return 0;
}