Answer the question
In order to leave comments, you need to log in
How to find an object in an image?
Good day to all.
There is the following problem. There is an image, as a rule it looks something like this:
On this image, you need to find and read the DataMatrix codes, these are those in black circles. I was looking for a ready-made open source solution. The following options have been found:
Mat binImage = new Mat(image.rows(), image.cols(), image.type());
Imgproc.GaussianBlur(image, binImage, new Size(5, 5), 5, 5);
Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 5, 0);
double iCannyLowerThreshold = 25;
double iCannyUpperThreshold = 70;
Imgproc.Canny(binImage, binImage, iCannyLowerThreshold, iCannyUpperThreshold);
Highgui.imwrite("lines/cannyImage_" + counter + ".bmp", binImage);
List<Line> result = new ArrayList<Line>();
Mat lines = new Mat();
int linesThreshold = 20;
int linesMinLineSize = 35;
int linesGap = 5;
Imgproc.HoughLinesP(binImage, lines, 1, Math.PI / 180, linesThreshold, linesMinLineSize, linesGap);
for (int x = 0; x < lines.cols(); x++) {
double[] vecHoughLines = lines.get(0, x);
if (vecHoughLines.length == 0)
break;
double x1 = vecHoughLines[0];
double y1 = vecHoughLines[1];
double x2 = vecHoughLines[2];
double y2 = vecHoughLines[3];
Point pt1 = new Point();
Point pt2 = new Point();
pt1.x = x1;
pt1.y = y1;
pt2.x = x2;
pt2.y = y2;
result.add(new Line(pt1, pt2));
Core.line(image, pt1, pt2, new Scalar(255, 0, 0, 255), 2);
}
Answer the question
In order to leave comments, you need to log in
Defined the circles, the QR code is supposed to be in the circles. Throw this QR code into a library that works with these codes, without aligning, clearing everything behind the circles
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question