contour

OpenCV: Get only black contours in a binary image with findContours

本小妞迷上赌 提交于 2019-12-13 20:25:10
问题 I am new to OpenCV, so please bear with me. Currently, I get contours of both white and black things in my binary image. I only want black contours though (so where the value is 0). Is there some kind of setting I can adjust to get this result? Or can I filter them? Also: cv.findContours() does return both the contours and a hierarchy. What is hierarchy used for? And lastsly: Contours seemingly consist of an array with multiple coordinates. What do they mean? 回答1: cv2.findContours finds all

calling contour without plotting it, python, pylab inline

冷暖自知 提交于 2019-12-13 13:22:42
问题 For an algorithm I am using contour, but I'm only interested in its collection of paths. Since I have called pylab inline from the start, and it is now too painful to rewrite the code without the inline (many functions have to be declared more carefully, like np.something() instead of something(), etc...), I was wondering if there is a way to call contour without it plotting the contour map ? Something like contour(image_matrix, 'No Show')? Regards 回答1: The following is a modified code i used

Blinking contour line

只谈情不闲聊 提交于 2019-12-13 06:41:43
问题 My program's objective is to identify the largest contour from a video camera and draw it with red line. I discovered that when the largest contour (aka largest_contours in my program) is detected, the contour's contour line will blink and sometime will interrupt the function to draw a red line around it (because the contour's line is not connected anymore so no more contour detected inside the image). My questions are: What is the reason for this problem to happen? How to avoid (or can we

OpenCV detecting a single symbol with multiple bounding boxes

倖福魔咒の 提交于 2019-12-13 03:07:40
问题 I am using OpenCV to put bounding boxes on handwritten math equation inputs. Currently, my code sometimes places multiple smaller bounding boxes around different parts of a singular image instead of creating one large box around the image. I'm not sure why this is happening. My current code to filter the image and find the contours to draw the bounding box is as follows: img = cv2.imread(imgpath) morph = img.copy() morph = cv2.fastNlMeansDenoising(img) kernel = cv2.getStructuringElement(cv2

How to access opencv contour point indexes in python?

落花浮王杯 提交于 2019-12-13 01:58:12
问题 Is there way to access the contour[i][j] in python? I am struggling to translate this c++ into python, because the data structures are different. It's being hard making comparisions static double distanceBtwPoints(const cv::Point a, const cv::Point b) { double xDiff = a.x - b.x; double yDiff = a.y - b.y; return std::sqrt((xDiff * xDiff) + (yDiff * yDiff)); } static int findNearestPointIndex(const cv::Point pt, const vector<Point> points) { int nearestpointindex = 0; double distance; double

R mapping filled.contour georeferencing interpolation

天大地大妈咪最大 提交于 2019-12-13 01:54:25
问题 I'm trying to make a map kind of like this, but with higher resolution, and less of a tile like appearance: Which used this code: samps <- read.csv("Petra_phytoplankton+POM_xydata_minusNAs_noduplicates.csv") #my data for sampling sites, contains a column of "lat" and a column of "lon" with GPS points in decimal degrees samps_test<-samps x<-samps_test$longitude y<-samps_test$latitude z<-samps_test$d13C ## interpolation using akima x0<-seq(min(x), max(x), length = 100) y0<-seq(min(y), max(y),

Opencv with Python: pointPolygonTest gives obviously wrong result

守給你的承諾、 提交于 2019-12-13 01:54:20
问题 I have a contour below. As I wanted to extract all the pixels inside this contour and black out everything else to remove noise, I used cv2.pointPolygonTest for the purpose. Below are the code I used to attempt to create the mask. inside_or_not = np.zeros(img.shape[:2],dtype = np.int32) for i in range(0,img.shape[0]): for j in range(0,img.shape[1]): inside_or_not[i,j] = cv2.pointPolygonTest(body_line,(i,j),False) Only 2 points were found to be inside the point. On top of that, I expect the

want to smooth a contour from a masked array

匆匆过客 提交于 2019-12-12 18:22:36
问题 I have a masked array which is used by matplotlib.plt.contourf to project a temperature contour on a glabal map. I was trying to smooth the contour, but unfortunately none of the proposed solutions seems to be able to handle masked array. I tested these solutions: -scipy.ndimage.gaussian_filter - moving averages scipy.ndimage.zoom none of them works(they count in the masked values also). Is there any way I can smooth my contour on maskedArray I have added this part after trying the proposed

removing part of a graphic in R

老子叫甜甜 提交于 2019-12-12 14:22:21
问题 Here is a picture obtained from R (the code is given below). I'd like to export it in pdf format . However, I'd like first to remove the legend bar on the right. As far as I know , there is no optional argument that controls this bar legend. How would you do? library(gplots) f <- function(x, y, theta) { num <- (x^(-theta) + y^(-theta) - 1)^(-1 / theta) denom <- x * y return(num / denom) } x <- y <- seq(0.01, 0.18, 0.01) z <- outer(x, y, FUN=f, theta=2/3) levels=seq(0, 36, 3) draw.contour <-

Compute contour of a binary image using matlab

牧云@^-^@ 提交于 2019-12-12 05:57:22
问题 I am trying to compute contour of a binary image. Currently i identify the first non zero and the last non zero pixel in the image through looping. Is there a better way? i have encountered few functions: imcontour(I) bwtraceboundary(bw,P,fstep,conn,n,dir) But the first doesn't return the x and y coordinates of the contour. The second function requires a seed point which i cannot provide. An example of the image is shown below. Thanks. 回答1: @rayryeng have already provided the correct answer.