opencv-contour

OpenCV - How to determine whether a given point is within a contour?

懵懂的女人 提交于 2020-04-30 07:36:27
问题 Given a random contour, how can I say if a given input point lies within the contour or not? I am sorry if it has a simple solution, but I am unable to figure it out. One idea I had was to use equation of lines, connect points and see if it is greater or smaller, etc. But that doesn't get me anywhere, as it depends on the position of line. 回答1: You can find a full solution to this problem using OpenCV here /// Get the contours vector<vector<Point> > contours; vector<Vec4i> hierarchy; Mat src

Check if two contours intersect?

守給你的承諾、 提交于 2020-04-13 11:15:06
问题 I have 2 contours ( cont1 and cont2 ) received from cv2.findContours() . How do I know if they intersect or not? I don't need coordinates, I only need a boolean True or False . I have attempted different ways and already tried to do a check with if ((cont1 & cont2).area() > 0): ... but got the error that the array has no method "Area()" ... cont1array = cv2.findContours(binary1, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[0] cont2array = cv2.findContours(binary2, cv2.RETR_LIST, cv2.CHAIN_APPROX

Check if two contours intersect?

ⅰ亾dé卋堺 提交于 2020-04-13 11:13:46
问题 I have 2 contours ( cont1 and cont2 ) received from cv2.findContours() . How do I know if they intersect or not? I don't need coordinates, I only need a boolean True or False . I have attempted different ways and already tried to do a check with if ((cont1 & cont2).area() > 0): ... but got the error that the array has no method "Area()" ... cont1array = cv2.findContours(binary1, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[0] cont2array = cv2.findContours(binary2, cv2.RETR_LIST, cv2.CHAIN_APPROX

Check if two contours intersect?

坚强是说给别人听的谎言 提交于 2020-04-13 11:12:16
问题 I have 2 contours ( cont1 and cont2 ) received from cv2.findContours() . How do I know if they intersect or not? I don't need coordinates, I only need a boolean True or False . I have attempted different ways and already tried to do a check with if ((cont1 & cont2).area() > 0): ... but got the error that the array has no method "Area()" ... cont1array = cv2.findContours(binary1, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[0] cont2array = cv2.findContours(binary2, cv2.RETR_LIST, cv2.CHAIN_APPROX

OpenCV, cv2.approxPolyDP() Draws double lines on closed contour

旧街凉风 提交于 2020-03-22 11:01:31
问题 I want to create some polygons out of this mask: image 1 - Mask So i created these contours with openCV findcontours(): image 2 - Contours When creating polygons I get these polygons: image 3 - Polygons As you can see some polygons are drawn using double lines. How do I prevent this? See my code: import glob from PIL import Image import cv2 import numpy as np # Let's load image = cv2.imread(path + "BigOneEnhanced.tif") # Grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Find Canny

Detecting small squares attached to something else on the image

£可爱£侵袭症+ 提交于 2020-03-03 07:35:47
问题 I want to detect small squares circled in red on the image. But the problem is that they are on another white line. I want to know how to separate those squares from the white line and detect them. I have used OpenCV Python to write the code. What I have done until now is that I cropped the image so that I get access only to the circular part of the image. Then I cropped the image to get the required part that is the white line. Then I used erosion so that the white line will vanish and the

Detecting small squares attached to something else on the image

蓝咒 提交于 2020-03-03 07:35:05
问题 I want to detect small squares circled in red on the image. But the problem is that they are on another white line. I want to know how to separate those squares from the white line and detect them. I have used OpenCV Python to write the code. What I have done until now is that I cropped the image so that I get access only to the circular part of the image. Then I cropped the image to get the required part that is the white line. Then I used erosion so that the white line will vanish and the

Center of mass in contour (Python, OpenCV)

 ̄綄美尐妖づ 提交于 2020-01-23 17:02:12
问题 I have this image: What I am trying to do is to detect the center of mass of the inner contour (number 3) inside it. This is the code I have right now: import cv2 import numpy as np im = cv2.imread("three.png") imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray, 127, 255, 0, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU) _, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) cnts = cv2.drawContours(im, contours[1], -1, (0, 255, 0), 1)

How can I select the pixels that fall within a contour in an image represented by a numpy array?

馋奶兔 提交于 2020-01-15 05:47:08
问题 I have a set of contour points drawn on an image which is stored as a 2D numpy array. The contours are represented by 2 numpy arrays of float values for x and y coordinates each. These coordinates are not integers and do not align perfectly with pixels but they do tell you the location of the contour points with respect to pixels. I would like to be able to select the pixels that fall within the contours. I wrote some code that is pretty much the same as answer given here: Access pixel values

How to crop the biggest object in image with python opencv?

为君一笑 提交于 2020-01-12 08:30:32
问题 I want to crop the biggest object in the image (Characters). This code only works if there is no line (shown in the first image). But I need to ignore the line and make the image of the second image. Only crop the biggest object image. import cv2 x1, y1, w1, h1 = (0,0,0,0) points = 0 # load image img = cv2.imread('Image.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale # threshold to get just the signature retval, thresh_gray = cv2.threshold(gray, thresh=100, maxval