opencv-contour

Convert contour paths to svg paths

倾然丶 夕夏残阳落幕 提交于 2019-12-21 14:54:30
问题 I am using openCV with python to extract contours from an image. Now I need to export these contour paths (list) as an svg paths. How can I achieve this ? code: ret,thresh = cv2.threshold(imgray,27,25,0) contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL , cv2.CHAIN_APPROX_TC89_L1) print(type(contours)) #type list 回答1: the problem has been solved as follows: c = max(contours, key=cv2.contourArea) #max contour f = open('path.svg', 'w+') f.write('<svg width="'+str(width)+'" height

Convert contour paths to svg paths

浪子不回头ぞ 提交于 2019-12-21 14:54:01
问题 I am using openCV with python to extract contours from an image. Now I need to export these contour paths (list) as an svg paths. How can I achieve this ? code: ret,thresh = cv2.threshold(imgray,27,25,0) contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL , cv2.CHAIN_APPROX_TC89_L1) print(type(contours)) #type list 回答1: the problem has been solved as follows: c = max(contours, key=cv2.contourArea) #max contour f = open('path.svg', 'w+') f.write('<svg width="'+str(width)+'" height

Improve contour detection with OpenCV (Python)

拜拜、爱过 提交于 2019-12-20 10:39:28
问题 I am trying to identify cards from a photo. I managed to do what I wanted on ideal photos, but I am now having hard time applying the same procedure with slightly different lighting, etc. So the question is about making the following contour detection more robust. I need to share a big part of my code for the takers to be able to make the images of interest, but my question relates only to the last block and image. import numpy as np import cv2 from matplotlib import pyplot as plt from mpl

Do contours returned by cv::findContours have a consistent orientation?

六眼飞鱼酱① 提交于 2019-12-20 09:58:37
问题 I am using OpenCV's cv::findContours function to extract contours in a binary image, in particular, I'm extracting a hierarchy of contours (using the CV_RETR_CCOMP flag). At some point in my further processing of those contours I need to rely on a consistent vertex orientation of these contours (i.e. counter-clockwise vs. clockwise) . Of course I can just determine that orientation myself using the sign of the contour's area (as computed by cv::contourArea(..., true)), but I wonder if that is

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

不打扰是莪最后的温柔 提交于 2019-12-19 09:15:07
问题 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

How to blackout the background of an image after doing contour detection using open in Python?

♀尐吖头ヾ 提交于 2019-12-13 22:26:31
问题 I've detected contours for an image using opencv python,now I should blackout the image outside the contour.Could anyone help me to do this? 回答1: Given your found contours, use drawContours to create a binary mask, in which your contours are filled. Dependent on how you do that (black image, white contours vs. white image, black contours), you set all pixels in your input image to 0 expect for the masked (or unmasked) ones. See the following code snippet for a visualization: import cv2 import

How to detect and draw contours using OpenCV in Python?

此生再无相见时 提交于 2019-12-13 12:32:33
问题 I wrote the following code to detect and draw contours: img = cv2.imread('test2.tif'); if not img is None: imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY); ret,thresh = cv2.threshold(imgray,127,255,0); contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE); #draw a three pixel wide outline cv2.drawContours(img,contours,-1,(0,255,0),3); And here is the error I received: Traceback (most recent call last): File "C:/Users/R.K.singh/Desktop/Image processing/intro-to

Remove an opencv contour from a list of contours [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-11 09:50:43
问题 This question already has answers here : Test if a numpy array is a member of a list of numpy arrays, and remove it from the list (3 answers) Closed last year . With opencv , I'm detecting contours and selecting some of them: CNTS = [] _, contours, _ = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for c in contours: if some_condition(c): CNTS.append(c) Then I'm looping over 2-subsets {c1, c2} of the list of contours, and removing some of them: TMP = CNTS[:] # copy it, to

Give contours from right to left in Opencv c++

淺唱寂寞╮ 提交于 2019-12-11 04:21:38
问题 I want to print center of contours with "findContours" function from right to left contours, in opencv c++. when i print centers, i see contours Not have particular order. Is there a way to implement an order to contours in opencv c++? 回答1: You can use: // Find all the contours vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours(Image, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE); sort(contours.begin(), contours.end(), Right_Left_contour_sorter()); and " Right

Opencv not finding all contours

情到浓时终转凉″ 提交于 2019-12-11 03:47:28
问题 I'm trying to find the contours of this image, but the method findContours only returns 1 contour, the contour is highlighted in image 2 . I'm trying to find all external contours like these circles where the numbers are inside. What am i doing wrong? What can i do to accomplish it? image 1 image 2 Below is the relevant portion of my code. thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN