Ask Your Question

Missing's profile - activity

2017-07-22 02:53:24 -0600 received badge  Good Answer (source)
2016-08-19 02:03:05 -0600 commented question how to use python to detect ellipse

I think you can't do that just with approxPolyDP(). Instead you could use some circularity attributes (inertia ratio), take a look at this article. Another option would be to use scikit-image, which provides an elliptical hough transform, see here.

2016-08-17 11:37:08 -0600 commented question getting 0xc000007b

You should be more specific with your question, how should anyone know what exactly you are trying to do? Nevertheless this often happens because of incompatibilities between 32 bit and 64 bit. So you could check if all your DLL's are either 32 or 64 bit.

2016-08-12 06:19:30 -0600 commented question how to calculate radius

What do you mean by "in case there is no signal"? The hough transform already provides you with the radii of the circles.

2016-07-27 08:51:46 -0600 commented question How do I add opencv_contrib to an existing homebrew installation

To my knowledge you can't. You have to recompile opencv with the contrib_modules.

2016-07-27 08:00:07 -0600 received badge  Nice Answer (source)
2016-07-27 03:21:52 -0600 commented question how can i train SVM

That is not really a problem for a SVM. To train a SVM you need features. This means you need to extract some information about the image. In your scenario such a feature would be the color of the car. And since you need to get the color of the car you don't need a SVM anymore. What is your solution to find the car in the image?

2016-07-26 06:41:36 -0600 answered a question how to retrieve all coordinates of pixels of specific colour in an image.

You can use the numpy.where() method to do that. Here is a minimal example:

import numpy as np

zeros = np.zeros((100, 100), dtype=np.uint8)
zeros[:5,:5] = 255

indices = np.where(zeros == [255])
print indices
coordinates = zip(indices[0], indices[1])
print coordinates

So here you see a 100x100 pixel black image where a little square in the upper left is set to white. By using the numpy.where() method I retrieved a tuple of two array (indices) where the first array contains the x-coordinates of the white points and the second array contains the y-coordinates of the white pixels. By using the zip() method you can get a list of tuples containing the points. You can convert this list to a numpy array by calling the numpy.asarray() function.

Best Regards

2016-07-26 04:36:11 -0600 commented question OpenCV convexhull points coordinates

Where exactly is your problem in getting the convex hull points? The OpenCV function convexHull() will give you an array of the points. Have a look at the documentation: Documentation

2016-07-25 21:11:04 -0600 received badge  Nice Question (source)
2016-07-21 04:22:05 -0600 commented question opencv_error_code-215_channels

The channels of your two images do not match. So you are trying to copy a bgr image to a grayscale image or something like that. Check the types of your images.

2016-07-21 02:48:32 -0600 commented question Image matching using goodFeaturesToTrack

BFMatcher needs keypoint descriptors to work. The goodFeaturesToTrack function only gives you strong corners, but no descriptors.

2016-07-20 02:38:14 -0600 commented question Opencv 3.1 capture from multiple cameras.

I dont't think that this is an OpenCV problem. It is more likely a hardware problem. USB webcams tend to use as much usb bandwidth as possible. So if your two cameras are connected to the same usb bus, the first webcam will take all the bandwidth and there is no space left for the second webcam. Maybe you could use two different usb hosts to connect both webcams.

2016-07-18 07:06:51 -0600 received badge  Student (source)
2016-07-18 02:08:13 -0600 answered a question Commercial Software using OpenCV

OpenCV is released under a BSD licence. This means that it is free to use for academical and commercial use. The modules in the opencv_contrib package are not free for commercial use (algorithms like SIFT, SURF).

Best Regards Missing

2016-07-15 04:42:00 -0600 asked a question Hand Posture Recognition using Machine Learning

Hey guys,

I am currently working on my thesis and for that I am trying to recognize different hand postures for controlling an embedded system. My first implementation used simple skin color segmentation, calculation of contours, convex hull, defects and so on. This works, but I am not satisfied, since it is not very robust. This approach also detects other skin colored objetcs and I don't want to compute all these things every frame.

Because of that I started to think about machine learning algorithms. I thought about using a Support Vector Machine for my task. My problem is that I don't really know what to use. Is a SVM a good choice for hand posture recognition or is another machine learning algorithm more appropriate? I am also unsure about what features to use for training my model. Currently I use SURF-Features, since SIFT is to slow. Are other features more suitable? And my last problem is the training set. What kind of images do I need to train my model?

So my questions are:

  • Is a Support Vector Machine a good choice for hand posture recognition?

  • What are good features to train the model?

  • What kind of images do I need for my training? How many for each class? Grayscale, Binary, Edges?

I know that these are no specific questions, but there is so many literature out there and I need some advide where to look at.

I am working with the OpenCV Python Bindings for my image processing and use the scikit package for the machine learning part.

EDIT

@Pedro Batista, first of all thank you very much for your detailed answer, I really appreciate that. The system should run in a laboratory environment. So the user has to interact with different devices and should be able to control some of these devices by hand postures/gestures. The background might be stable, but it is no simple white/black background. For the moment I assume that the user places his hand close in front of the camera.

Yesterday I made a minimal example with a SVM. I took some sample images of three different hand postures (Open Hand, Fist and two fingers). I took only 20 images for every posture of size 320*240. The size and distance of the hand was nearly the same in every image.

After that I segmented the hand by simple threshold in the YCrCb color space and performed some smoothing and opening/closing operations. By calculating the biggest contour (which I assume is the hand) I got two features, the area of the contour and the perimeter. Calculating more features should be no problem, like convexity defects, angles and so on. I used these two features to train my SVM and got the following classification (area on the x axis and perimeter on the y axis).

image description

So in this case the simple classification works quite well, but at the moment I just worked with an idealized situation. For the moment ... (more)

2016-07-12 02:22:36 -0600 received badge  Critic (source)
2016-07-12 02:22:10 -0600 commented answer Crop rectangle and apply transformation from image?

I don't know how to check if your contour is a rectangle since the contour is not good. What are these noisy lines at the top left corner? You have to get a clean contour of the paper sheet to determine the shape of it.

2016-07-12 02:03:53 -0600 commented question capture not remaining open

Hmm for me your code works fine. Maybe your cap.read() returns False for ret . This would break your while-loop and end the program. You could try to change the break in your else-path to pass

2016-07-12 01:54:10 -0600 commented answer Crop rectangle and apply transformation from image?

You can check the shape by using approxPolyDP(). This functions approximates a polygonal curve of the contour. This meens you get four points if the contour is a rectangle, three points if it is a triangle and so on. But this will not work for your image, because your contour does not fit the paper sheet correctly. You need to get the contour right like in my example above.

2016-07-11 06:39:41 -0600 answered a question Crop rectangle and apply transformation from image?

So i wrote some Python code to get the contour of the paper sheet.

import numpy as np
import cv2

# Original image
image = cv2.imread('images/sheet.jpg')
# Resize
image = cv2.resize(image, (500,500))
draw = np.zeros_like(image)
# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Get black and white image
ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))

# Some erosions and dilations to remove noise.
thresh = cv2.erode(thresh, kernel, iterations=4)
thresh = cv2.dilate(thresh, kernel, iterations=4)

# Get Contours of binary image
im, cnts, hier = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# Find the biggest contour
max_area = -1
max_c = 0
for i in range(len(cnts)):
    contour = cnts[i]
    area = cv2.contourArea(contour)
    if (area > max_area):
        max_area = area
        max_c = i
contour = cnts[max_c]

# Get minAreaRect
rect = cv2.minAreaRect(contour)
box = cv2.boxPoints(rect)
box = np.int0(box)


# Draw contour and minAreaRect
cv2.drawContours(image, [box],-1, (0, 255, 0), 2)
cv2.drawContours(image, [contour], -1, (255,0,0), 2)
cv2.imshow('Sheet', image)

cv2.waitKey(0)
cv2.destroyAllWindows()

After that the image looks like this (blue is the contour and green is the rectangle around the contour:

image description

2016-07-11 03:00:29 -0600 commented question Crop rectangle and apply transformation from image?

No your image named "gray"...This is the black and white image you use to calculate the contours. This image should just contain the white paper sheet.

2016-07-11 01:02:03 -0600 commented question Crop rectangle and apply transformation from image?

Could you post your image that you use findContours() on? Your contour follows along the border of the image and not the paper sheet. Seems yout threshold is not good enough.

2016-07-08 03:56:27 -0600 commented question Crop rectangle and apply transformation from image?

Simply iterate over your contours and retrieve the contour area by calling contourAea(contour) and store the biggest one. With minAreaRect()you get the rotated rectangle for that contour. If you want to extract that rectangle take a look at that question here: http://answers.opencv.org/question/49...

2016-07-07 03:41:25 -0600 commented question Crop rectangle and apply transformation from image?

You already calculated the contours of your image. The paper sheet should be the biggest contour. So find the biggest contour in your image and you get your paper sheet. With minAreaRect() you can calculate a rotated rectangle around that contour.

2016-07-04 02:50:18 -0600 answered a question error C2065: 'SiftFeatureDetector' : undeclared identifier

In OpenCV 2.4 the SURF and SIFT algorithms moved to nonfree folder. Use this instead:

#include <opencv2/nonfree/features2d.hpp>
2016-07-02 10:58:27 -0600 commented answer 3.1.0 Face Recognition Algorithm? c++

Since you can't compile the opencv_contrib modules alone, you have to re-compile the opencv core modules with the above mentioned option. You can read about the steps in the README of the repository.

2016-07-01 03:49:53 -0600 commented question Fourier Transform vs Template Matching

What exactly do you want to compare? The Fourier Transform is used to find the frequency domain of an image and template matching is used to find the location of a template in a larger image, these are different topics.

2016-06-30 06:39:17 -0600 received badge  Teacher (source)
2016-06-28 09:03:49 -0600 commented answer Replace a range of colors with a specific color in python

Okay my fault. The problem here is that the call to numpy.all() tests whether the condition is true for the whole array, meaning it checks if every pixel in an image row is black and that is obviously not true in your case. So try it without the numpy.all() function. Just use

black_mask[np.where(black_mask == [0])] = [255]
2016-06-28 06:19:49 -0600 commented answer Replace a range of colors with a specific color in python

Hey, yes because your original image is in RGB color format. The masked image is just black and white, so you just have one color channel. Change your code to:

black_mask[np.where((black_mask == [0]).all(axis = 1))] = [255]
2016-06-28 05:11:16 -0600 received badge  Supporter (source)
2016-06-28 05:04:32 -0600 commented answer Replace a range of colors with a specific color in python

Your first attemp should work correctly. Did you import numpy correctly as np? Do you use your image or the image i created with np.zeros?

import cv2
import numpy as np

    image = np.zeros((400,400,3), dtype="uint8")
    raw = image.copy()
    image[np.where((image==[0,0,0]).all(axis=2))] = [255,255,255]
    cv2.imshow('Test', image)
    cv2.imshow('Test2', raw)
    if cv2.waitKey() == ord('q'):
        cv2.destroyAllWindows()

This is the complete code for the example and it turns a black image into a white one.

2016-06-28 02:20:10 -0600 answered a question Replace a range of colors with a specific color in python

You can simply use numpy to do this.

image = np.zeros((400,400,3), dtype="uint8")
image[np.where((image==[0,0,0]).all(axis=2))] = [255,255,255]

This will change all pixels in image that have a value of [0,0,0] to [255,255,255].

After your inRange() operation you get an image in black and white, so you have just one color channel. In that case you have to use:

image[np.where((image==[0]).all(axis=1))] = [255]

This will change all rows in your image that are completely black to white. To change not only the rows that are completely black omit the call to numpy.all(). Use:

image[np.where(image == [0])] = [255]

Best regards

2016-06-27 14:56:14 -0600 received badge  Editor (source)
2016-06-27 14:55:39 -0600 answered a question 3.1.0 Face Recognition Algorithm? c++

The methods for face recognition were moved to the opencv_contrib repository at https://github.com/Itseez/opencv_contrib

You need to compile OpenCV with

cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>

and then you can use Eigenfaces, Fisherfaces and LBPH.

Best regards

2016-06-24 15:05:49 -0600 commented question Can I draw a square region of interest and crop it from original image using OpenCV functions?

I think the answer to this question will solve your problem: http://answers.opencv.org/question/49...

2016-06-22 07:23:08 -0600 commented answer Obtaining rect dimension when clicked anywhere in the box ?

I just added the two rectangles for demo purposes. If you have the edges in your images it will also work, provided that your input image to findContours() is in grayscale and your rectangles are represented white on black background. The code returns the top left and bottom right coordinates of the rectangle you clicked. You easily can compute the dimension of it from hat.

2016-06-22 04:49:06 -0600 answered a question Obtaining rect dimension when clicked anywhere in the box ?

You could use findContours() to get the contours of your rectangles. If you click somewhere in your image you get the coordinates of the click. With pointPolygonTest() you now can check if you clicked inside one of the contours.

import cv2
import numpy as np

contours = None

def callback(event, x, y, flags, param):
    global contours
    if (event == cv2.EVENT_LBUTTONDOWN):
        for cnt in contours:
            res = cv2.pointPolygonTest(cnt, (x,y), True)
            if (res > 0):
                x,y,w,h = cv2.boundingRect(cnt)
                print (x,y), (x+w-1,y+h-1)


cv2.namedWindow('test')
cv2.setMouseCallback('test', callback)
image = np.zeros((400, 400, 3), np.uint8)
cv2.rectangle(image, (10, 10), (100, 100), (255,255,255), 1)
cv2.rectangle(image, (200, 200), (300, 300), (255,255,255), 1)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cnts, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

cv2.imshow('test', image)
if cv2.waitKey() == ord('1'):
    cv2.destroyAllWindows()

This might be not the best solution, since you check for every contour, but it will work. Best regards

2016-06-22 02:42:25 -0600 commented question Obtaining rect dimension when clicked anywhere in the box ?

Please make clear what you want to achieve! The dimensions of a box drawn on an image or what?

2016-06-21 00:50:52 -0600 commented question How to get raw data using OpenCV APIs

You could try to set CV_CAP_PROP_CONVERT_RGB property of your camera to false. However this not seems to work everytime, but maybe it will work for you.

2016-06-20 06:19:43 -0600 commented question Quit if There's No Match

Template matching returns a grayscale image where each pixel denotes how much the neighbourhood of that pixel matches with the template. With minMaxLoc() you get the point with the best match. You now could simply check this maximum point and if it is below a certain value (you specif this value) you throw an exception. I never used template matching on my own, so this is just an idea to solve this your issue.

2016-06-20 04:16:07 -0600 commented question How to stream video from IP camera using openCV python

There are some examples for that on the web. I did not try it on my own, but maybe this will work for you: https://gist.github.com/thearn/5562029

2016-06-20 04:03:15 -0600 commented question Quit if There's No Match

Do you use the Template Matching Function in OpenCV or another algorithm? I'm not very familiar with it, but if i'm right you get a matrix back which indicates where the highest matches were detected. So maybe you could use a threshold value for the detected maximum matching value.