How to reconstruct damaged barcode
I want to refill erased barcode like this
i'have used morphology open with a vertical rectangle kernel but the result it's not pretty.
i need a image like this
I want to refill erased barcode like this
i'have used morphology open with a vertical rectangle kernel but the result it's not pretty.
i need a image like this
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)
#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;
}
Asked: 2017-09-15 07:06:43 -0600
Seen: 4,862 times
Last updated: Oct 21 '20
can we expect, that the damaged bars are absolutely vertical at least ?
sum of columns?
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 )
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
Now i need an computer vision expert view point :D
do you have more data ? is this some ean13 code (or any known format, that would be helpful to know ?)
the barcode use CODE39
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.