Ask Your Question
1

How to reconstruct damaged barcode

asked 2017-09-15 07:06:43 -0500

Tostik gravatar image

updated 2020-10-21 07:15:02 -0500

I want to refill erased barcode like this image description

i'have used morphology open with a vertical rectangle kernel but the result it's not pretty.

i need a image like this image description

image description

edit retag flag offensive close merge delete

Comments

can we expect, that the damaged bars are absolutely vertical at least ?

berak gravatar imageberak ( 2017-09-15 07:11:59 -0500 )edit
1

sum of columns?

LBerger gravatar imageLBerger ( 2017-09-15 07:13:39 -0500 )edit
1

Just a suggestion not sure if its an efficient way ; travel horizontally and for every black pixel you encounter scan the vertical line --> if black pixel count is very small that could be noise if not draw line( keep track of drawn lines )

Ziri gravatar imageZiri ( 2017-09-15 07:53:31 -0500 )edit

The damaged bars are absolutely vertical. Scan image is complex just count it's no suffisant. Now i've filled blank zone in the lines with morphological transformations and straigth line kernel.

After blank zone are filled i use a classical barcode scanner

Tostik gravatar imageTostik ( 2017-09-15 11:31:09 -0500 )edit

Now i need an computer vision expert view point :D

Tostik gravatar imageTostik ( 2017-09-15 11:32:15 -0500 )edit

do you have more data ? is this some ean13 code (or any known format, that would be helpful to know ?)

berak gravatar imageberak ( 2017-09-15 13:05:28 -0500 )edit

the barcode use CODE39

Tostik gravatar imageTostik ( 2017-09-15 15:48:20 -0500 )edit
1

If you know the bars are vertical and the errors are fairly evenly distributed across the entire image, you might try making a histogram of the sums of the brightness values of the pixels each column and feed that to a bar code decode algorithm. Alternatively, you could try to locate and decode the text using OCR.

opalmirror gravatar imageopalmirror ( 2018-11-14 14:25:23 -0500 )edit

1 answer

Sort by » oldest newest most voted
4

answered 2017-09-15 11:57:08 -0500

just tested the code below, maybe you will try to improve it. ( your image is not aligned perfectly . it must be aligned perfectly to get correct result)

image description

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp> 
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    Mat img = imread("e:/test/bar.png");
    if (img.empty())
        return -1;

    Mat gray, reduced_h;
    cvtColor(img, gray, CV_BGR2GRAY);
    gray = gray > 127;
    Mat kernel(5, 1, CV_8U, Scalar(1));
    erode(gray, gray, kernel,Point(-1,-1),4);

    reduce(gray, reduced_h, 0, REDUCE_AVG);

    Mat reduced_h_graph = img.clone();
    copyMakeBorder(reduced_h_graph, reduced_h_graph, 0, 100, 0, 0,BORDER_CONSTANT,Scalar(0,0,0));

    for (int i = 0; i < img.cols; i++)
    {
        if (reduced_h.at<uchar>(0, i) > 150)
        line(reduced_h_graph, Point(i, reduced_h_graph.rows-101), Point(i, reduced_h_graph.rows), Scalar(255, 255, 255), 1);
    }

    imshow("reduced_h_graph", reduced_h_graph);
    waitKey(0);
    return 0;
}
edit flag offensive delete link more

Comments

Thank you. I look this

Tostik gravatar imageTostik ( 2017-09-15 15:55:35 -0500 )edit

It works great. thank you very much. Do you know solution to align line before complete the image?

Tostik gravatar imageTostik ( 2017-09-15 21:07:04 -0500 )edit

maybe i will try something about aligning. is there some more sample images?

sturkmen gravatar imagesturkmen ( 2017-09-15 21:15:47 -0500 )edit

opencvtest.cpp:21:30: error: ‘REDUCE_AVG’ was not declared in this scope reduce(gray, reduced_h,0,REDUCE_AVG);

nageshd88 gravatar imagenageshd88 ( 2018-11-14 13:08:01 -0500 )edit

opencv version? maybe CV_REDUCE_AVG

sturkmen gravatar imagesturkmen ( 2018-11-14 13:32:52 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2017-09-15 07:06:43 -0500

Seen: 1,614 times

Last updated: Oct 21