OPENCV based on the color of the license plate location

Source: Internet
Author: User

OPENCV based on the color of the license plate location

http://blog.csdn.net/superdont/article/details/24936341

OPENCV based on the color of the license plate location2014-05-03 22:05 4626 People read Comments (3) favorite reports Classification:image Processing (a)OpenCV (in)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use Color properties:

[CPP]View PlainCopy  
  1. Mat Srcimage=imread ("image/t10.jpg");
  2. Mat Srcshowimage;
  3. Srcimage.copyto (Srcshowimage);
  4. //imshow ("a", srcimage);
  5. int i,j;
  6. int cpointb,cpointg,cpointr;
  7. For (i=1;i<srcimage.rows;i++)
  8. For (j=1;j<srcimage.cols;j++)
  9. {
  10. Cpointb=srcimage.at<vec3b> (I,J) [0];
  11. Cpointg=srcimage.at<vec3b> (I,J) [1];
  12. Cpointr=srcimage.at<vec3b> (I,J) [2];
  13. if (cpointb>80&cpointr<80&cpointg<80) //extract blue, set the area to black
  14. {
  15. Srcimage.at<vec3b> (I,J) [0]=0;
  16. Srcimage.at<vec3b> (I,J) [1]=0;
  17. Srcimage.at<vec3b> (I,J) [2]=0;
  18. }
  19. Else if (cpointb>200&cpointr>200&cpointg>200) //Extract white, set it to black
  20. {
  21. Srcimage.at<vec3b> (I,J) [0]=0;
  22. Srcimage.at<vec3b> (I,J) [1]=0;
  23. Srcimage.at<vec3b> (I,J) [2]=0;
  24. }
  25. Else
  26. {
  27. Srcimage.at<vec3b> (I,J) [0]=255;
  28. Srcimage.at<vec3b> (I,J) [1]=255;
  29. Srcimage.at<vec3b> (I,J) [2]=255;
  30. }
  31. }
  32. Cvtcolor (Srcimage,srcimage, Cv_bgr2gray);
  33. Threshold (srcimage,srcimage,127, 255,cv_thresh_binary);
  34. //Use the difference method to remove irrelevant areas.
  35. For (i=1;i<srcimage.rows;i++)
  36. For (j=1;j<srcimage.cols-1;j++)
  37. {
  38. Srcimage.at<uchar> (i,j) =srcimage.at<uchar> (i,j+1)-srcimage.at<uchar> (I,J);
  39. }
  40. Threshold (srcimage,srcimage,127, 255,CV_THRESH_BINARY_INV);  //By the two value of the way to take the reverse.
  41. //erode (Srcimage,srcimage,mat (5,5,cv_8u), point ( -1,-1), 2); Corrosion
  42. //Dilate (Src,src,mat (5,5,cv_8u), point ( -1,-1), 2); //expansion
  43. //Morphologyex (Src,src,morph_open,mat (3,3,cv_8u), point ( -1,-1), 1); Open Operation
  44. //Morphologyex (Src,src,morph_close,mat (3,3,cv_8u), point ( -1,-1), 1); Closed Operation
  45. Erode (Srcimage,srcimage,mat (3,3,cv_8u), point ( -1,-1), 5);
  46. Threshold (SRCIMAGE,SRCIMAGE,127,255,CV_THRESH_BINARY_INV);
  47. Imshow ("a", srcimage);
  48. vector<vector<point> > contours;
  49. Vector<vec4i> hierarchy;
  50. Findcontours (srcimage, contours, hierarchy, cv_retr_external, Cv_chain_approx_simple, point (0, 0));
  51. Scalar color = scalar (rng.uniform (0, 255), Rng.uniform (0,255), Rng.uniform (0,255));
  52. For ( int i = 0; i < contours.size (); i++)
  53. {
  54. //How to use the bounding box
  55. Cvrect arect = Boundingrect (Contours[i]);
  56. int tmparea=arect.height*arect.height;
  57. if ((double) arect.width/(double)arect.height>2) && ((Double) arect.width/(double) arect.height<6) && tmparea>=2000&&tmparea<=25000)
  58. {
  59. Rectangle (Srcshowimage,cvpoint (ARECT.X,ARECT.Y), Cvpoint (Arect.x+arect.width, arect.y+arect.height), color,2);
  60. //cvdrawcontours (DST, contours, color, color,-1, 1, 8);
  61. }
  62. }
  63. Imshow ("Da", Srcshowimage);

The effect is as follows:

Colors can be considered more nuanced, or considered to be implemented in other color spaces.

OPENCV based on the color of the license plate location

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.