Ask Your Question

How to delete a QR CODE white margins?

asked 2014-02-25 02:18:11 -0500

smilencetion gravatar image

Hi,I'm new to OpenCV, is there a way to delete a QR CODE white margins?thx

just like from

image description

image description

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2014-02-25 04:14:13 -0500

Haris gravatar image

updated 2014-02-25 10:34:44 -0500

  1. Create a mask image for the area to be cropped

image description

2.Find the bounding box for mask, you should do the following

image description

3.Crop the source using bound rect.

image description


   Mat src=imread("barcode.png",1);
   Mat thr,gray;
   threshold( gray, thr, 50, 255, CV_THRESH_BINARY_INV );

   Size kernalSize (21,21);
   Mat element = getStructuringElement (MORPH_RECT, kernalSize, Point(1,1)  );
   morphologyEx( thr, thr, MORPH_CLOSE, element );

   vector< vector <Point> > contours;
   vector< Vec4i > hierarchy;
   findContours( thr, contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE );
   Rect ROI=boundingRect(contours[0]); //Contour size  should bealways 1

   Mat crop=src(ROI);
edit flag offensive delete link more


excellent,ty so much

smilencetion gravatar imagesmilencetion ( 2014-02-25 04:23:52 -0500 )edit

@smilencetion, so mark it as solved !

berak gravatar imageberak ( 2014-02-25 04:29:03 -0500 )edit

Question Tools


Asked: 2014-02-25 02:18:11 -0500

Seen: 877 times

Last updated: Feb 25 '14