Fill outside of contour with white OpenCv Python - python

I am trying to find the contour with the largest area and fill the outside of the contour with white. I have looked at this Question
The solution works well when using many contours but when I try to use it with one contour it only shows the contour with the inside and outside black. I am trying to rather create a mask that only leaves the interior area of the contour. I am using max(contours, key=cv2.contourArea) to get the largest contour. Using OpenCv, Python

Related

How to fill in an area below detected contours in Python OpenCV?

I am looking to fill the area under a boundary with white color. I basically have an image with the red boundary detected through the findContours method
I am now looking at filling the area below this detected red boundary with white color. This would allow me to distinguish between the area below the red boundary and the area above for a histogram computation.
Can someone help me with this? Open to suggestions outside OpenCV as well, if it's easier to implement.
You are drawing after findContours operation. you can get the points(x,y) you are painting and you can calculate it with a simple row to column ratio.

How to eliminate small contour areas using opencv

I have tried to create a contour map in python with a fault using KNearestNeighbors as the interpolation method. However, the graph came back as with multiple small contour areas, which I want to eliminate:
I tried to use OpenCV to find all enclosed contour lines and set a boundary value as the maximum area, then eliminate all areas smaller than the boundary value.
However, I seemed to fail using the findContours method, as it only found contours around the fault. All other contours failed to present. The resulting graph and my code are as follows:
img = cv2.imread('contor_line.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(gray,contours,-1,(0,0,255),1)
cv2.imshow("gray", gray)
cv2.waitKey(0)
This is my first time using OpenCV, so thank you for helping.
Try using canny before you find contours, or threshold your image, which will make finding contours easier and better.

Python opencv aeroplane condensation trail detection

My task is to detect aeroplane condensation trails on the blue sky and deleting everything else from the picture, but I have to leave a 10-pixel wide area around the trails.
I have managed to draw the contours of the condensation trails based on colour using a mask and cv2.drawContours but I'm stuck with creating that 10-pixel sky blue area around it-basically I have to scale up the contour line.
Is it possible to scale up contours drawn by the cv2.drawContours command?
Since you already have a list of points on the contour, you can easily draw a 10-pixel thick line on it by using the line function between consecutive points (look at the thickness parameter). To fill the rest of the area inside the contour, look at the fillPoly function.

OpenCV: How can I calculate the area of a white region?

I have a black image with a big white spot on it and I want to calculate the area of this white spot. Which is the best way to calculate this ? I'm using OpenCV in Python.
To find the Area follow these steps:
Apply thresholding & Binarize the input image.
Find Contours.
Find the Area of Contours by using cv.ContourArea();
refer this example for further reference.

Python Opencv - Find black dots inside contours

I'm using the python wrapper for OpenCV 2.1. (I can't use any external library)
Does anyone know how can I find a black dot put inside other 2 concentric black shapes?
Now I'm using cv.FindCountours to detect the black areas, but then I don't know how to discard the 2 concentric shapes and keep only the internal dot
link to image: http://img848.imageshack.us/img848/2797/visiodrawing11.png
First update the OpenCV to 2.3.1
1) find all the contours after inverting image color.
2) Find their area.
3) Select the contour with minimum area or minimum perimeter.
4) That will be the center point. You can copy it to another image.

Categories

Resources