Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int projection() {
- int width = 400;
- int height = 300;
- cv::Mat src = cv::Mat(height, width, CV_32FC1);
- src = cv::Scalar(0);
- cv::rectangle(src, cv::Rect((src.cols / 2) - 20, (src.rows/ 2) - 20, 40, 40), cv::Scalar(255), -1);
- cv::circle(src, cv::Point(src.rows / 2 + 40, src.cols / 2 + 40), 40, cv::Scalar(255), 3);
- cv::Mat rotated = cv::Mat(height, width, CV_32FC1);
- //cv::imshow("src", src);
- //cv::waitKey(5);
- cv::Mat dst = cv::Mat(height, width, CV_32FC1);
- dst = cv::Scalar(0.0f);
- cv::Mat dst_norm = cv::Mat(height, width, CV_32FC1);
- float diagonalLength = ceil( sqrt(SQR(height) + SQR(width)));
- cv::Mat stepDst = cv::Mat(height, diagonalLength, CV_32FC1);
- cv::Mat stepDstRotated = cv::Mat(height, width, CV_32FC1);
- for (int i = 0; i < 360; i++)
- {
- cv::Mat rotMat = cv::getRotationMatrix2D(cv::Point2f(width / 2, height / 2), i, 1);
- cv::warpAffine(src, rotated, rotMat, rotated.size());
- cv::imshow("rotated", rotated);
- for (int y = 0; y < src.rows; y++) {
- float rSum = 0;
- for (int x = 0; x < src.cols; x++)
- {
- rSum += rotated.at<float>(y, x);
- }
- for (int x = 0; x < stepDst.cols; x++)
- {
- stepDst.at<float>(y, x) = rSum;
- }
- }
- rotMat = cv::getRotationMatrix2D(cv::Point2f(stepDst.cols / 2, stepDst.rows / 2), i, 1);
- cv::warpAffine(stepDst, stepDst, rotMat, stepDst.size());
- int marginX = (stepDst.cols - stepDstRotated.cols) / 2;
- for (int x = 0; x < stepDstRotated.cols; x++)
- {
- for (int y = 0; y < stepDstRotated.rows; y++)
- {
- stepDstRotated.at<float>(y, x) = stepDst.at<float>(y, x + marginX);
- }
- }
- cv::normalize(stepDstRotated, stepDstRotated, 0, 1, cv::NORM_MINMAX);
- dst += stepDstRotated;
- cv::imshow("stepDst", stepDstRotated);
- cv::normalize(dst, dst_norm, 0, 1, cv::NORM_MINMAX);
- cv::imshow("dst", dst_norm);
- cv::waitKey(5);
- }
- cv::normalize(dst, dst, 0, 1, cv::NORM_MINMAX);
- cv::waitKey(5);
- cv::imshow("dst", dst);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement