Good day.

They gave the task: to find the angle of inclination of the object (in my case, the blades of the helicopter) and output all the video stream. Use VS2015 and OpenCV 2.4.13 Found an example on this site: Algorithm for determining the angle of rotation of the image . It helped a lot but there were some problems and some I decided, some didn't:

In the beginning she complained about the string

pts_mat.at<double>(j,0) = pts[j].x; 

solved the problem by changing the variable pts [j] .x to contoue [j] .x and y, respectively. Later I solved the necessary libraries.

 #include <iostream> #include <opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp> using namespace std; using namespace cv; double angle; int main(); { Mat src_mat = imread("E:/work/project/opencv/Find_object/Find_object/blade2.jpg", CV_LOAD_IMAGE_COLOR); imshow("blade", src_mat); if (src_mat.empty() == NULL) { cout << "File not find!"; } Mat gry_mat; cvtColor(src_mat, gry_mat, COLOR_BGR2GRAY); threshold(gry_mat, gry_mat, 150, 255, CV_THRESH_BINARY); vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours(gry_mat, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE); int sz = static_cast<int>(contours.size()); for (int i = 0, n = contours.size(); i < n; ++i) { const vector<Point> &contour = contours.at(i); // Отсеиваем слишком маленькие, либо слишком большие. double area = contourArea(contour); if (area < 1e2 || 1e5 < area) continue; // Строим буфер для PCA. int sz = static_cast<int>(contour.size()); Mat pts_mat = Mat (sz, 2, CV_64FC1); for (int j = 0; j < pts_mat.rows; ++j) { pts_mat.at<double>(j, 0) = contour[j].x; pts_mat.at<double>(j, 1) = contour[j].y; } PCA pca(pts_mat, Mat(), CV_PCA_DATA_AS_ROW); // В отдельный вектор выносим собственные вектора, // полученные при помощи PCA. vector<Point2d> eigen_vecs(2); for (int j = 0; j < 2; ++j) { eigen_vecs[j] = Point2d(pca.eigenvectors.at<double>(j, 0), pca.eigenvectors.at<double>(j, 1)); } // Искомый угол. angle = atan2(eigen_vecs[0].y, eigen_vecs[0].x); cout << "Angin[" << i << "] =" << angle << "\n"; } return angle; } 

everything works, calculates, but an error is displayed enter image description here

comes out after the work of the entire program. Help me please.

Required dlls: core, highgui, imgproc;

  • Most likely, the given error is damage to the heap. Check work with memory (array boundaries, double deletion, etc). - Mikalai Ramanovich
  • Try to create a minimal reproducible example . If in the process of its creation the error is not detected on its own, it will be easier for other Community participants to help you. - αλεχολυτ
  • Thank you very much! commented out almost all the code, and began to repair it. announcements made of the cycle and it worked. - Afro Men

0