opencv-contour

Fill the outside of contours OpenCV

 ̄綄美尐妖づ 提交于 2019-12-10 13:22:53
问题 I am trying to color in black the outside region of a contours using openCV and python language. Here is my code : contours, hierarchy = cv2.findContours(copy.deepcopy(img_copy),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) areas = [cv2.contourArea(c) for c in contours] max_index = np.argmax(areas) cnt=contours[max_index] # how to fill of black the outside of the contours cnt please? ` 回答1: Here's how you can fill an image with black color outside of a set of contours: import cv2 import numpy img =

OpenCV FindContours finds no contours on android

半世苍凉 提交于 2019-12-10 13:16:42
问题 I'm trying to find contours of an image, using OpenCV on android build with Xamarin (details about versions below). I cannot get the FindCountours function to return any contours (the list is empty), even when using a pseudo image like below. Another problem is that there is one contour in the hierachy object. It works when run from Python on Windows. Does anybody know what could be the cause? Mat aoiHsv = new Mat(new Size(80, 80), CvType.Cv8uc3); for (int i = 20; i < 40; i++) { for (int j =

opencv - plot contours in an image

你离开我真会死。 提交于 2019-12-08 14:39:27
I am trying to draw contour around an image. I can see that contours being found but I am not able to draw the outline. The color of the contour seem to be either of the two (black and white) colors. import cv2 import numpy as np import matplotlib.pyplot as plt from skimage import io %matplotlib inline im = io.imread('http://matlabtricks.com/images/post-35/man.png') plt.imshow(im) imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) plt.figure() plt.imshow(imgray) #Contoured image ret,thresh = cv2.threshold(imgray, 120,255,cv2.THRESH_BINARY) image, contours, hierarchy = cv2.findContours(thresh,cv2

OpenCV findContours are not in order

一笑奈何 提交于 2019-12-08 11:42:04
问题 When using OpenCV findContours method, how come the contours are not found in order? inputImage = cv2.imread("randomImage.jpg",0) im2, contours, hierarchy = cv2.findContours(inputImage.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) j=1 for cnt in reversed(contours): letter = inputImage[y:y+h, x:x+w] cv2.imwrite(str(j)+"sub/"+str(k)+'.png', letter) k+=1 The input image consists of a few letters, for example "abcde". However, when the contours are saved to file they are saved in a random

How to draw contours of each segmented object

只谈情不闲聊 提交于 2019-12-07 19:58:57
问题 I apply watershed segmentation to detect touching objects and it works okay doing that. Now, I would like to draw contours of each object, so I can get their length, area, moments etc.. But the objects in the result of the segmentation are still touching. So, I fail to draw contours of each one. How can I draw contours of each object? #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat src

detecting multi color document with OpenCV4Android

谁说胖子不能爱 提交于 2019-12-07 15:33:07
问题 I am new to OpenCv with Android.I am trying to make an application which auto detects documents using OpenCv - 2.4.13 . In my app, there is a functionality of detection documents (like a Scanbot app) and then prospect it to document. So, far I am able to detect documents with single colour or documents which are clearly distinguishable from background. But the problem arises when the document is of multi-color. To clearly understand the problem , I have attached an image: As you can see, the

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

半世苍凉 提交于 2019-12-06 10:47:35
问题 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.

How to draw contours of each segmented object

时光怂恿深爱的人放手 提交于 2019-12-06 08:47:09
I apply watershed segmentation to detect touching objects and it works okay doing that. Now, I would like to draw contours of each object, so I can get their length, area, moments etc.. But the objects in the result of the segmentation are still touching. So, I fail to draw contours of each one. How can I draw contours of each object? #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat src = imread("source.png"); // Create binary image from source image Mat srcGray; cvtColor(src, srcGray, CV

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

Deadly 提交于 2019-12-06 00:26:38
问题 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

Contouring a binary mask with OpenCV / Python

折月煮酒 提交于 2019-12-05 21:44:17
With Python and OpenCV I am detecting contours of a binary mask: import numpy as np import cv2 import matplotlib.pyplot as plt mask = np.zeros(20000, dtype=np.uint8).reshape(100, 200) mask[5:-5,5:-5] = 255 mask[10:70,40:80] = 0 plt.subplot(121) plt.imshow(mask, cmap='Greys_r', interpolation='none') _, contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE, offset=(0, 0)) Resulting in an expected behaviour : plt.subplot(122) cv2.drawContours(mask, contours, -1, (127, 127, 127), 2) plt.imshow(mask, cmap='Greys_r', interpolation='none') plt.show() However, I