Eject an object on a piece of paper

From the images of the tools on a piece of paper I will ask you to find their outline contour to vectorize them.

I am new to computer vision problems and the only thing I was thinking about is OpenCV and border detection.

The result is better than I imagined, it is still very unreliable, especially if the original image is not "perfect".

I took 2 photos of the key that they gave me.

After playing with opencv binding for node , I get the following:

good wrench contour

Then, I tried with a less good picture:

enter image description here

It is completely useless. I can get something a little better by modifying Canny thresold, but this should be automated (given that the image is relatively correct).

So, I have a few questions:

  • ? GrabCut ? Grabcut Canny? , , GrabCut , .
  • . approxPolyDP, .
  • , -, , approxPolyDP. ?
  • , . OpenCL, , , , ? - , , ? , , , , ( ).
  • Canny thresold, . ?
  • , , . ? ( btw!)

:

const cv = require('opencv');

const lowThresh = 90;
const highThresh = 90;
const nIters = 1;

const GRAY   = [120, 120, 120];
const WHITE = [255, 255, 255];

cv.readImage('./files/viv1.jpg', function(err, im) {
  if (err) throw err;

  width = im.width()
  height = im.height()
  if (width < 1 || height < 1) throw new Error('Image has no size');

  const out = new cv.Matrix(height, width);
  im.convertGrayscale();
  im_canny = im.copy();
  im_canny.canny(lowThresh, highThresh);
  im_canny.dilate(nIters);

  contours = im_canny.findContours();

  let maxArea = 0;
  let biggestContour;

  for (i = 0; i < contours.size(); i++) {
    const area = contours.area(i);
    if (area > maxArea) {
      maxArea = area;
      biggestContour = i;
    }

    out.drawContour(contours, i, GRAY);
  }

  const arcLength = contours.arcLength(biggestContour, true);
  contours.approxPolyDP(biggestContour, 0.001 * arcLength, true);

  out.drawContour(contours, biggestContour, WHITE, 5);

  out.save('./tmp/out.png');
  console.log('Image saved to ./tmp/out.png');
});
+4
2

, . - , , ​​.., . , .

opencv ++: http://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/histogram_equalization/histogram_equalization.html

,

EDIT: , (?). : , , , x = 10 x = 800 (). , x = 10 x = 800. , , , .

+1

. , / (, , ). Adathresh , , Canny .

, findContours CV_CHAIN_APPROX, ,

+1

Source: https://habr.com/ru/post/1680336/


All Articles