Search code examples
c#opencvemgucv

Scan a image with emgu cv


So i have an image that has been processed with the sobel method, and now i need to extract that image.

My problem is how can i start scanning the image from the mid line uo and down line by line, and when the number of edge is less than 60, record that coordinate to crop the image.

The image in question is a barcode, and this method should work for extracting only the bars. The problem is the implementation with emgu cv.

Update:

I am following the method described in this paper: http://bit.ly/HUWdcy

This question is referent to the C. Image Extraction Chapter


Solution

  • Check the cv::threshold and cv::reduce functions.

    First wil create a binary map out of your edge image, with black on the stripes, and white on background.

    Like this small example:

    After edges

    1 70  0 0 85  128 99  0
    1 70  0 0 85  128 99  0
    1 70  0 0 85  128 99  0
    1 70  0 0 85  120 99  0
    1 74  0 0 85  138 99  0
    1 80  0 0 85  128 99  0
    1 72  0 0 85  128 99  0
    

    After threshold

    0 255 0 0 255 255 255 0
    0 255 0 0 255 255 255 0
    0 255 0 0 255 255 255 0
    0 255 0 0 255 255 255 0
    0 255 0 0 255 255 255 0
    0 255 0 0 255 255 255 0
    0 255 0 0 255 255 255 0
    

    Second function can be used to "project" the image on one of its dimensions, using CV_MAX, or CV_SUM, or CV_AVG, and you will have the barcodes stored in a row

    Example for reduce with SUM:

    0 1785 0 0 1785 1785 1785 0
    

    Now, reapply a threshold:

    0 1 0 0 1 1 1 0