霍夫变换检测直线

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44.
pt2.x = cvRound(rho/a); pt2.y = 0;
cvLine(color_dst,pt1,pt2,CV_RGB(255,0,0),1,8);
lines = cvHoughLines2(dst,storage,CV_HOUGH_PROBABILISTIC,1,CV_PI/180,80,30,5); for (i=0;i<lines->total;i++) { CvPoint *line = (CvPoint *)cvGetSeqElem(lines,i); cvLine(color_dst,line[0],line[1],CV_RGB(255,0,0),1,CV_AA);
#include<cv.h> #include <highgui.h> #include <math.h>
Байду номын сангаас
int main(void) { IplImage *src = cvLoadImage("D:\\xgmiao\\image\\1.jpg",0); if (src) { IplImage *dst = cvCreateImage(cvGetSize(src),8,1); IplImage *color_dst = cvCreateImage(cvGetSize(src),8,3); CvMemStorage *storage = cvCreateMemStorage(); CvSeq *lines = 0; int i ; cvCanny(src,dst,50,200,3);
cvCvtColor(dst,color_dst,CV_GRAY2BGR); #if 0 lines = cvHoughLines2(dst,storage,CV_HOUGH_STANDARD,1,CV_PI/180,150,0,0);
for (i=0;i<lines->total;i++) { float *line = (float *)cvGetSeqElem(lines,i); float rho = line[0]; float theta = line[1]; CvPoint pt1,pt2; double a = cos(theta); double b = sin(theta); if (fabs(a)<0.001) { pt1.x = pt2.x = cvRound(rho); pt1.y = 0; pt2.y = color_dst->height; } else if (fabs(b)<0.001) { pt1.y = pt2.y = cvRound(rho); pt1.x = 0; pt2.x = color_dst->width; } else { pt1.x = 0; pt1.y = cvRound(rho/b);
cvNamedWindow("Source"); cvShowImage("Source",src);
cvNamedWindow("Hough"); cvShowImage("Hough",color_dst);
cvWaitKey(0);
cvReleaseImage(&src); cvReleaseImage(&dst); cvReleaseImage(&color_dst); cvReleaseMemStorage(&storage);
cvDestroyAllWindows();
return 1;
45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. } } } #endif } #else }
相关文档
最新文档