opencv-contour

Navigate through hierarchy of contours found by FindContours method?

雨燕双飞 提交于 2019-11-30 21:44:17
This must be simple for C++ developers using OpenCV directly. However what I'm using is Emgu (an OpenCV wrapper for .NET) and in the latest version we have the method CvInvoke.FindContours returning void, the output result is passed by parameter reference and is of type VectorOfVectorOfPoint . Here is a simple call: //outputResult is a VectorOfVectorOfPoint CvInvoke.FindContours(inputImage, outputResult, null, RetrType.Tree, ChainApproxMethod.ChainApproxSimple); For RetrType.List mode, we can just convert the result to some array of arrays and loop through all the contours easily. However here

Get area within contours Opencv Python?

浪子不回头ぞ 提交于 2019-11-30 11:48:11
问题 I have used an adaptive thresholding technique to create a picture like the one below: The code I used was: image = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 45, 0) Then, I use this code to get contours: cnt = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[0] My goal is to generate a mask using all the pixels within the outer contour, so I want to fill in all pixels within the object to be white. How can I do this? I have tried

How to detect/find checkbox contours using OpenCV

我是研究僧i 提交于 2019-11-30 04:37:34
问题 I have several images for which i need to do OMR by detecting checkboxes using computer vision. I'm using findContours to draw contours only on the checkboxes in scanned document. But the algorithm extracts each and every contours of the text. from imutils.perspective import four_point_transform from imutils import contours import numpy as np import argparse, imutils, cv2, matplotlib import matplotlib.pyplot as plt import matplotlib.image as mpimg image = cv2.imread("1.jpg") gray = cv2

Get area within contours Opencv Python?

扶醉桌前 提交于 2019-11-30 00:30:28
I have used an adaptive thresholding technique to create a picture like the one below: The code I used was: image = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 45, 0) Then, I use this code to get contours: cnt = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[0] My goal is to generate a mask using all the pixels within the outer contour, so I want to fill in all pixels within the object to be white. How can I do this? I have tried the code below to create a mask, but the resulting mask seems no different then the image after

Dealing with contours and bounding rectangle in OpenCV 2.4 - python 2.7

寵の児 提交于 2019-11-29 20:44:08
I am working with openCv and python and I am dealing with Structural Analysis and Shape Descriptors. I have found this blog: http://opencvpython.blogspot.it/2012/06/contours-2-brotherhood.html that's very helpful and I have tried with a black and white image to drawing a bounding rectangle and it works. But now from an image i extract, for example, the yellow color and on that i would like to draw a bounding rectangle. The problem is that the black and white image is not uniform it has some noise and like that the code doesn't recognize the whole shape. And this is the code: import numpy as np

OpenCV sharpen the edges (edges with no holes)

筅森魡賤 提交于 2019-11-29 05:17:26
I am trying to detect the biggest/larger rectangular shape and draw bounding box to the detected area. In my use case, very often (and not always) the object that represent the rectangle shape is in color white and the background is also in color very similar to white. Before detecting contours, I have preprocessed the image in order to detect perfect edge. My problem is that I can't detect edges perfectly and i have a lot of noise even after blurring and using 'adaptive threshold' or 'threshold'. The original image i have used for contours detection I have tried different way to detect

Want to find contours -> ValueError: not enough values to unpack (expected 3, got 2), this appears

匆匆过客 提交于 2019-11-28 06:53:07
My simple python code is this import cv2 img=cv2.imread('Materials/shapes.png') blur=cv2.GaussianBlur(img,(3,3),0) gray=cv2.cvtColor(blur,cv2.COLOR_BGR2GRAY) returns,thresh=cv2.threshold(gray,80,255,cv2.THRESH_BINARY) ret,contours,hierachy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: area=cv2.contourArea(cnt) #contour area if (area>1220): cv2.drawContours(img,[cnt],-1,(0,255,0),2) cv2.imshow('RGB',img) cv2.waitKey(1000) print(len(cnt)) import numpy as np contours=np.array(contours) print(contours) This worked fine. But recently without me even making any

openCV 2.4.10 bwlabel - connected components

我是研究僧i 提交于 2019-11-27 23:23:29
Here is the original code from matlab: % Calculate each separated object area cDist=regionprops(bwImg, 'Area'); cDist=[cDist.Area]; % Label each object [bwImgLabeled, ~]=bwlabel(bwImg); % Calculate min and max object size based on assumptions on the color % checker size maxLabelSize = prod(size(imageData)./[4 6]); minLabelSize = prod(size(imageData)./[4 6]./10); % Find label indices for objects that are too large or too small remInd = find(cDist > maxLabelSize); remInd = [remInd find(cDist < minLabelSize)]; % Remove over/undersized objects for n=1:length(remInd) ri = bwImgLabeled == remInd(n);

OpenCV sharpen the edges (edges with no holes)

╄→尐↘猪︶ㄣ 提交于 2019-11-27 17:02:52
问题 I am trying to detect the biggest/larger rectangular shape and draw bounding box to the detected area. In my use case, very often (and not always) the object that represent the rectangle shape is in color white and the background is also in color very similar to white. Before detecting contours, I have preprocessed the image in order to detect perfect edge. My problem is that I can't detect edges perfectly and i have a lot of noise even after blurring and using 'adaptive threshold' or

Want to find contours -> ValueError: not enough values to unpack (expected 3, got 2), this appears

风格不统一 提交于 2019-11-27 01:16:35
问题 My simple python code is this import cv2 img=cv2.imread('Materials/shapes.png') blur=cv2.GaussianBlur(img,(3,3),0) gray=cv2.cvtColor(blur,cv2.COLOR_BGR2GRAY) returns,thresh=cv2.threshold(gray,80,255,cv2.THRESH_BINARY) ret,contours,hierachy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: area=cv2.contourArea(cnt) #contour area if (area>1220): cv2.drawContours(img,[cnt],-1,(0,255,0),2) cv2.imshow('RGB',img) cv2.waitKey(1000) print(len(cnt)) import numpy as np