Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /////////////////////////////LAB3/////////////////////////////
  2. void hough()
  3. {
  4.  
  5. char fname[MAX_PATH];
  6. while (openFileDlg(fname))
  7. {
  8. Mat src = imread(fname, CV_LOAD_IMAGE_GRAYSCALE);
  9. int D = sqrt(src.rows*src.rows + src.cols*src.cols);
  10. int r = D + 1;
  11. int maxHough = 0;
  12. Mat Hough(r, 360, CV_32SC1, Scalar(0));
  13.  
  14.  
  15. for (int i = 0; i < src.rows; i++){
  16. for (int j = 0; j < src.cols; j++){
  17. if (src.at<uchar>(i, j) == 255){
  18. for (int theta = 0; theta < 360; theta++){
  19. double angle = theta *CV_PI / 180;
  20. int ro = j*cos(angle) + i*sin(angle);
  21. if (ro>0 && ro < D){
  22. Hough.at<int>(ro, theta)++;
  23. }
  24. }
  25. }
  26. }
  27. }
  28.  
  29. for (int i = 0; i < r; i++){
  30. for (int j = 0; j < 360; j++){
  31. if (Hough.at<int>(i, j)> maxHough){
  32. maxHough = Hough.at<int>(i, j);
  33.  
  34. }
  35. }
  36. }
  37.  
  38.  
  39. Mat houghImg;
  40. Hough.convertTo(houghImg, CV_8UC1, 255.f / maxHough);
  41. imshow("Hough", houghImg);
  42. waitKey(0);
  43.  
  44. }
  45.  
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement