Advertisement
arxeiss

DZO - Projection

Dec 7th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. int projection() {
  2.     int width = 400;
  3.     int height = 300;
  4.  
  5.     cv::Mat src = cv::Mat(height, width, CV_32FC1);
  6.     src = cv::Scalar(0);
  7.     cv::rectangle(src, cv::Rect((src.cols / 2) - 20, (src.rows/ 2) - 20, 40, 40), cv::Scalar(255), -1);
  8.     cv::circle(src, cv::Point(src.rows / 2 + 40, src.cols / 2 + 40), 40, cv::Scalar(255), 3);
  9.  
  10.     cv::Mat rotated = cv::Mat(height, width, CV_32FC1);
  11.     //cv::imshow("src", src);
  12.     //cv::waitKey(5);
  13.    
  14.  
  15.     cv::Mat dst = cv::Mat(height, width, CV_32FC1);
  16.     dst = cv::Scalar(0.0f);
  17.     cv::Mat dst_norm = cv::Mat(height, width, CV_32FC1);
  18.     float diagonalLength = ceil( sqrt(SQR(height) + SQR(width)));
  19.     cv::Mat stepDst = cv::Mat(height, diagonalLength, CV_32FC1);
  20.     cv::Mat stepDstRotated = cv::Mat(height, width, CV_32FC1);
  21.  
  22.     for (int i = 0; i < 360; i++)
  23.     {
  24.         cv::Mat rotMat = cv::getRotationMatrix2D(cv::Point2f(width / 2, height / 2), i, 1);
  25.         cv::warpAffine(src, rotated, rotMat, rotated.size());
  26.         cv::imshow("rotated", rotated);
  27.  
  28.         for (int y = 0; y < src.rows; y++) {
  29.             float rSum = 0;
  30.             for (int x = 0; x < src.cols; x++)
  31.             {
  32.                 rSum += rotated.at<float>(y, x);
  33.             }
  34.  
  35.             for (int x = 0; x < stepDst.cols; x++)
  36.             {
  37.                 stepDst.at<float>(y, x) = rSum;
  38.             }
  39.         }
  40.        
  41.         rotMat = cv::getRotationMatrix2D(cv::Point2f(stepDst.cols / 2, stepDst.rows / 2), i, 1);
  42.         cv::warpAffine(stepDst, stepDst, rotMat, stepDst.size());
  43.         int marginX = (stepDst.cols - stepDstRotated.cols) / 2;
  44.         for (int x = 0; x < stepDstRotated.cols; x++)
  45.         {
  46.             for (int y = 0; y < stepDstRotated.rows; y++)
  47.             {
  48.                 stepDstRotated.at<float>(y, x) = stepDst.at<float>(y, x + marginX);
  49.             }
  50.         }
  51.         cv::normalize(stepDstRotated, stepDstRotated, 0, 1, cv::NORM_MINMAX);
  52.         dst += stepDstRotated;
  53.  
  54.         cv::imshow("stepDst", stepDstRotated); 
  55.        
  56.         cv::normalize(dst, dst_norm, 0, 1, cv::NORM_MINMAX);
  57.         cv::imshow("dst", dst_norm);
  58.         cv::waitKey(5);
  59.     }
  60.  
  61.     cv::normalize(dst, dst, 0, 1, cv::NORM_MINMAX);
  62.     cv::waitKey(5);
  63.     cv::imshow("dst", dst);
  64.  
  65.     return 1;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement