opencv-contour

OpenCV Assertion failed: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S)

和自甴很熟 提交于 2019-12-05 19:49:10
I have found the following code on this website : import os import os.path import cv2 import glob import imutils CAPTCHA_IMAGE_FOLDER = "generated_captcha_images" OUTPUT_FOLDER = "extracted_letter_images" # Get a list of all the captcha images we need to process captcha_image_files = glob.glob(os.path.join(CAPTCHA_IMAGE_FOLDER, "*")) counts = {} # loop over the image paths for (i, captcha_image_file) in enumerate(captcha_image_files): print("[INFO] processing image {}/{}".format(i + 1, len(captcha_image_files))) # Since the filename contains the captcha text (i.e. "2A2X.png" has the text "2A2X

Contour Axis for Image

大憨熊 提交于 2019-12-04 15:59:30
问题 For a radiographic scan, I have been able to acquire the contours. I would be interested to find the center axis. How could I do it in python? Here is my code for contours: import cv2 img = cv2.imread("A.png") imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(img,60,200) contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) hierarchy = hierarchy[0] cv2.drawContours(img, contours, -1, (255,0,0), 3) cv2.imshow('img',img) cv2.waitKey(0) cv2

cv2.drawContours() - unfill circles inside characters (Python, OpenCV)

谁说胖子不能爱 提交于 2019-12-04 15:33:18
As suggested by @Silencer, I used the code he posted here to draw contours around the numbers in my image. At some point, working with numbers like 0,6,8,9 I saw that their inside contours (the circles) are being filled as well. How can I prevent this ? Is there a min/max area of action to set for cv2.drawContours() so I can exclude the inner area ? I tried to pass cv2.RETR_EXTERNAL but with this parameter only the whole external area is considered. The code is this (again, thanks Silencer. Was searching for this for months..): import numpy as np import cv2 im = cv2.imread('imgs\\2.png')

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

夙愿已清 提交于 2019-12-04 14:59:26
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=255, type=cv2.THRESH_BINARY) # find where the signature is and make a cropped region points = np.argwhere

Having difficulties detecting small objects in noisy background. Any ways to fix this?

此生再无相见时 提交于 2019-12-04 05:49:18
I am trying to make a computer vision program in which it would detect litter and random trash in a noisy background such as the beach (noisy due to sand). Original Image: Canny Edge detection without any image processing: I realize that a certain combination of image processing technique will help me accomplish my goal of ignoring the noisy sandy background and detect all trash and objects on the ground. I tried to preform median blurring, play around and tune the parameters, and it gave me this: It preforms well in terms of ignoring the sandy background, but it fails to detect some of the

OpenCV : How to find the pixels inside a contour in c++

倾然丶 夕夏残阳落幕 提交于 2019-12-03 16:06:12
Suppose if we are working on an image, is there any way to access the pixels inside the contour? I have already found the contour using the function findContours() and even found the moments but I couldn't find the pixels inside the contour. Any suggestions are Welcome!! Thank you! As @Miki already mentioned you can use connectedComponents to perform a labeling. Then you iterate through the bounding box of your object like @Amitay Nachmani suggested. But instead of using pointPolygonTest you can check if the value at your current positions matches your current label Here is a small example:

Contour Axis for Image

无人久伴 提交于 2019-12-03 09:12:01
For a radiographic scan, I have been able to acquire the contours. I would be interested to find the center axis. How could I do it in python? Here is my code for contours: import cv2 img = cv2.imread("A.png") imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(img,60,200) contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) hierarchy = hierarchy[0] cv2.drawContours(img, contours, -1, (255,0,0), 3) cv2.imshow('img',img) cv2.waitKey(0) cv2.destroyAllWindows() I am probably making this world a slightly worse place by answering a "gimme the working

How to check if point is placed inside contour? [closed]

别说谁变了你拦得住时间么 提交于 2019-12-03 07:56:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I have drawn a contour around extreme points. Inside polygon figure I have others points. How to check if they are inside contour? 回答1: You can use the cv2.pointPolygonTest() function available in OpenCV. For example: dist = cv2.pointPolygonTest(cnt,(50,50),True) In this example we

Access pixel values within a contour boundary using OpenCV in Python

一笑奈何 提交于 2019-12-03 07:30:48
问题 I'm using OpenCV 3.0.0 on Python 2.7.9. I'm trying to track an object in a video with a still background, and estimate some of its properties. Since there can be multiple moving objects in an image, I want to be able to differentiate between them and track them individually throughout the remaining frames of the video. One way I thought I could do that was by converting the image to binary, getting the contours of the blobs (tracked object, in this case) and get the coordinates of the object

How to check if point is placed inside contour? [closed]

≡放荡痞女 提交于 2019-12-02 21:25:14
I have drawn a contour around extreme points. Inside polygon figure I have others points. How to check if they are inside contour? You can use the cv2.pointPolygonTest() function available in OpenCV. For example: dist = cv2.pointPolygonTest(cnt,(50,50),True) In this example we are checking whether the coordinate (50, 50) is present withing the contour cnt dist returns one of the following three: Positive value if the point is inside the contour Negative value if the point is outside the contour Zero if the point is on the contour Within the function cv2.pointPolygonTest() the third parameter