Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////LAB3/////////////////////////////
- void hough()
- {
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
- int D = sqrt(src.rows*src.rows + src.cols*src.cols);
- int r = D + 1;
- int maxHough = 0;
- Mat Hough(r, 360, CV_32SC1, Scalar(0));
- for (int i = 0; i < src.rows; i++){
- for (int j = 0; j < src.cols; j++){
- if (src.at<uchar>(i, j) == 255){
- for (int theta = 0; theta < 360; theta++){
- double angle = theta *CV_PI / 180;
- int ro = j*cos(angle) + i*sin(angle);
- if (ro>0 && ro < D){
- Hough.at<int>(ro, theta)++;
- }
- }
- }
- }
- }
- for (int i = 0; i < r; i++){
- for (int j = 0; j < 360; j++){
- if (Hough.at<int>(i, j)> maxHough){
- maxHough = Hough.at<int>(i, j);
- }
- }
- }
- Mat houghImg;
- Hough.convertTo(houghImg, CV_8UC1, 255.f / maxHough);
- imshow("Hough", houghImg);
- waitKey(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement