Note that there are some explanatory texts on larger screens.

plurals
  1. POOpencv: Fill color in a contoured image
    primarykey
    data
    text
    <p>thanks for reading this in advance.</p> <p>I'm doing a credit card OCR related project, one step of which requires filling colors to an already contoured image.</p> <p>Sample images include:</p> <p><img src="https://i.stack.imgur.com/DPBhY.png" alt=""></p> <p>My goal is to fill the white space black:</p> <p><img src="https://i.stack.imgur.com/xuIjD.png" alt=""></p> <p>Although it seems straightforward, I have failed to find a satisfying solution. </p> <p>I was trying out the <code>findContours</code> function, but I found it very confusing. After running the following function:</p> <pre><code>findContours( cvMatImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) ); </code></pre> <p>Strangely enough, not only the contour points were not correctly extracted, but also, the original input image seemed to have its own color inverted.</p> <p><strong>Any input regarding how I should complete my goal, or how to correctly use <code>findContours</code> function is greatly appreciated.</strong></p> <h2>Update:</h2> <p>Thanks a lot for your kind input. </p> <p>In fact, the image included in my question has already been binarized -- and also I have applied an "adaptive thresholding" procedure to the image.</p> <p>The original image looks like: <code>http://i.stack.imgur.com/DkIKt.png</code></p> <pre><code>CGColorSpaceRef colorSpace = CGImageGetColorSpace(self.CGImage); CGFloat cols = self.size.width; CGFloat rows = self.size.height; Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to data cols, // Width of bitmap rows, // Height of bitmap 8, // Bits per component cvMat.step[0], // Bytes per row colorSpace, // Colorspace kCGImageAlphaNoneSkipLast | kCGBitmapByteOrderDefault); // Bitmap info flags CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage); CGContextRelease(contextRef); CGColorSpaceRelease(colorSpace); Mat cvImage_gray, cvImage_threshold; cvtColor(cvImageOrg, cvImage_gray, CV_RGB2GRAY); //Binarize adaptiveThreshold(cvImage_gray, cvImage_threshold, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, neighbor, threshRed); //Adaptive threshold </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload