I wrote the following code to detect and draw contours: And here is the error I received: Traceback (most recent call last): File “C:/Users/R.K.singh/Desktop/Image processing/intro-to-contours.py”, line 10, in contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE); ValueError: too many values to unpack What is wrong? I am using Python 2.7 and OpenCV 3.1.0 Answer In order to emphasize Selchuk’s point, the syntax involving OpenCV 3.x
Tag: image-processing
Convert a binary image to 2D array or Matrix in Python?
I’m new to image processing and I’m really having a hard time understanding stuff…so the idea is that how do you create a matrix from a binary image in python? to something like this: It not the same image though the point is there. Thank you for helping, I appreciate it cheers Answer Using cv2 -Read more here Using skimage
How to set coordinates when cropping an image with PIL?
I don’t know how to set the coordinates to crop an image in PILs crop(): I tried with gThumb to get coordinates, but if I take an area which I would like to crop, I can only find position 194 336. Could someone help me please? This is my picture: I wish to crop to this: Answer How to set
Normalizing images in OpenCV produces black image?
I wrote the following code to normalize an image using NORM_L1 in OpenCV. But the output image was just black. How to solve this? Answer If you want to change the range to [0, 1], make sure the output data type is float.
Detect white background on images using python
Is there a way to tell whether an image as a white background using python and what could be a good strategy to get a “percentage of confidence” about this question? Seems like the literature on internet doesn’t cover exactly this case and I can’t find anything strictly related. The images I want to analyze are typical e-commerce website product
Problems in traversing contours in python using OpenCV library
I am designing an algorithm in which I have to traverse through every contour in an image and apply a condition on it. I am using OpenCV library to do this. And the code is as follows: The error is: Answer I have never used h_next but whenever I’ve iterated over contours has worked. It appears that you’re mixing the
Access pixel values within a contour boundary using OpenCV in Python
I’m using OpenCV 3.0.0 on Python 2.7.9. I’m trying to track an object in a video with a still background, and estimate some of its properties. Since there can be multiple moving objects in an image, I want to be able to differentiate between them and track them individually throughout the remaining frames of the video. One way I thought
Implement MATLAB’s im2col ‘sliding’ in Python
Q: How to speed this up? Below is my implementation of Matlab’s im2col ‘sliding’ with the additional feature of returning every n’th column. The function takes an image (or any 2 dim array) and slides from left to right, top to bottom, picking off every overlapping sub-image of a given size, and returning an array whose columns are the sub-images.
How to get the Signal-to-Noise-Ratio from an image in Python?
I am filtering an image and I would like to know the SNR. I tried with the scipy function scipy.stats.signaltonoise() but I get an array of numbers and I don’t really know what I am getting. Is there any other way to get te SNR of my image? Answer UPDATE: (for those who don’t read linked material in the comments)
OpenCV Python: cv2.findContours – ValueError: too many values to unpack
I’m writing an opencv program and I found a script on another stackoverflow question: Computer Vision: Masking a human hand When I run the scripted answer, I get the following error: The code: Any help is appreciated! Answer I got the answer from the OpenCV Stack Exchange site. Answer THE ANSWER: I bet you are using the current OpenCV’s master