contour
What is the algorithm that opencv uses for finding contours?
If you read the documentation it is mentioned this function implements the algorithm of: Suzuki, S. and Abe, K., Topological Structural Analysis of Digitized Binary Images by Border Following. CVGIP 30 1, pp 32-46 (1985) OpenCV is open source if you want to see how this is implemented just need to read the code: https://github.com/opencv/opencv/blob/master/modules/imgproc/src/contours.cpp#L1655 … Read more
Contour/imshow plot for irregular X Y Z data
Does plt.tricontourf(x,y,z) satisfy your requirements? It will plot filled contours for irregularly spaced data (non-rectilinear grid). You might also want to look into plt.tripcolor(). import numpy as np import matplotlib.pyplot as plt x = np.random.rand(100) y = np.random.rand(100) z = np.sin(x)+np.cos(y) f, ax = plt.subplots(1,2, sharex=True, sharey=True) ax[0].tripcolor(x,y,z) ax[1].tricontourf(x,y,z, 20) # choose 20 contour levels, … Read more
How to crop away convexity defects?
This approach works only on points. You don’t need to create masks for this. The main idea is: Find defects on contour If I find at least two defects, find the two closest defects Remove from the contour the points between the two closest defects Restart from 1 on the new contour I get the … Read more
OpenCV Python: cv2.findContours – ValueError: too many values to unpack
I got the answer from the OpenCV Stack Exchange site. Answer THE ANSWER: I bet you are using the current OpenCV’s master branch: here the return statements have changed, see http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours. Thus, change the corresponding line to read: _, contours, _= cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) Or: since the current trunk is still not stable and you … Read more
matplotlib – extracting data from contour lines
For a given path, you can get the points like this: p = cs.collections[0].get_paths()[0] v = p.vertices x = v[:,0] y = v[:,1]
Python : 2d contour plot from 3 lists : x, y and rho?
You need to interpolate your rho values. There’s no one way to do this, and the “best” method depends entirely on the a-priori information you should be incorporating into the interpolation. Before I go into a rant on “black-box” interpolation methods, though, a radial basis function (e.g. a “thin-plate-spline” is a particular type of radial … Read more
How to crop the internal area of a contour?
It is unclear in your question whether you want to actually crop out the information that is defined within the contour or mask out the information that isn’t relevant to the contour chosen. I’ll explore what to do in both situations. Masking out the information Assuming you ran cv2.findContours on your image, you will have … Read more
Why does pyplot.contour() require Z to be a 2D array?
Looking at the documentation of contour one finds that there are a couple of ways to call this function, e.g. contour(Z) or contour(X,Y,Z). So you’ll find that it does not require any X or Y values to be present at all. However in order to plot a contour, the underlying grid must be known to … Read more
Plotting contours on an irregular grid
Here are some different possibilites using base R graphics and ggplot. Both simple contours plots, and plots on top of maps are generated. Interpolation library(akima) fld <- with(df, interp(x = Lon, y = Lat, z = Rain)) base R plot using filled.contour filled.contour(x = fld$x, y = fld$y, z = fld$z, color.palette = colorRampPalette(c(“white”, “blue”)), … Read more