Setting Region of interest hand - c++

I am working on cursor control using hand gestures. I have segmented my hand using opencv backprojection combined with backgroundsubtractorMOG. What I want to know is , How to set the ROI as a rectangle around my palm. Using this rectangle I want to calculate the average convexity defects, within the rectangle and use this to differentiate the different hand gesture. Any Ideas, I am useing Opencv in C++.

What you can do is to train a HoG classifier and do detectMultiScale.. The result would be a Rect that would contain the hand.

Related

Detecting a rectangular hole using PCL

Using PCL, I'm trying to detect and localize a rectangular cut from a large steel frame(img below):
Now I'm using the Concave hull class, and I do get the outlines from the rectangle. However, the outer borders of the camera view also follow.
I used a passthrough filter to get rid of the borders, however that only works in specific cases.
What I'm asking is, do you happen to know any methods that could give a better result?
For the holes, they are not always at the same height or location. But they are of a standard size(+/- 1 cm). A size criteria can eliminate false detections.
This is a gazebo simulated model, and the point cloud captured from a simulated kinect using ROS.
Using PCL, I used SAC planar segmentation, then extract a concave hull. As seen on the image, the edges of the camera view are also considered as a concave.
pcl::SACSegmentation<pcl::PointXYZ> segmentation;
segmentation.setOptimizeCoefficients (true);
segmentation.setModelType(pcl::SACMODEL_PLANE);
segmentation.setMethodType(pcl::SAC_RANSAC);
segmentation.setMaxIterations(1000);
segmentation.setDistanceThreshold(0.01);
segmentation.setInputCloud(cloud_ptr);//breytti
segmentation.segment(*inliers, *coefficients);
pcl::ConcaveHull<pcl::PointXYZ> chull;
chull.setInputCloud (cloud_projected);
chull.setAlpha (0.1);
chull.reconstruct (*cloud_hull, hullPolygons);
Eigen::Vector4f centroid;//new object for centroid calculation
pcl::PointXYZ minpt, maxpt;//min max boundary of new cloud
pcl::compute3DCentroid(*cloud_hull, centroid);
pcl::getMinMax3D(*cloud_hull,minpt,maxpt);
To sum it up, looking for a robust method or ideas to detect a rectangular cut from the frame.
Thanks
An alternative tool could be to use CloudCompare. In version 2.12 alpha, Tools> Sand box (research) > find biggest inner rectangle 2D it can be used to detect rectangular holes.

Detect ball/circle in OpenCV (C++)

I am trying to detect a ball in an filtered image.
In this image I've already removed the stuff that can't be part of the object.
Of course I tried the HoughCircle function, but I did not get the expected output.
Either it didn't find the ball or there were too many circles detected.
The problem is that the ball isn't completly round.
Screenshots:
I had the idea that it could work, if I identify single objects, calculate their center and check whether the radius is about the same in different directions.
But it would be nice if it detect the ball also if he isn't completely visible.
And with that method I can't detect semi-circles or something like that.
EDIT: These images are from a video stream (real time).
What other method could I try?
Looks like you've used difference imaging or something similar to obtain the images you have..? Instead of looking for circles, look for a more generic loop. Suggestions:
Separate all connected components.
For every connected component -
Walk around the contour and collect all contour pixels in a list
Suggestion 1: Use least squares to fit an ellipse to the contour points
Suggestion 2: Study the curvature of every contour pixel and check if it fits a circle or ellipse. This check may be done by computing a histogram of edge orientations for the contour pixels, or by checking the gradients of orienations from contour pixel to contour pixel. In the second case, for a circle or ellipse, the gradients should be almost uniform (ask me if this isn't very clear).
Apply constraints on perimeter, area, lengths of major and minor axes, etc. of the ellipse or loop. Collect these properties as features.
You can either use hard-coded heuristics/thresholds to classify a set of features as ball/non-ball, or use a machine learning algorithm. I would first keep it simple and simply use thresholds obtained after studying some images.
Hope this helps.

Find ROI in a webcam image

I have a video sequence of which one frame is shown below as shown below.
I was trying to use corner detection to find the edges of the rectangle on the sheet of paper.
I am using the Shi-Tomasi corner detector for the same. However it detects a number of other things that I don't need from the background of the image. How can I narrow down my ROI to only the sheet of paper.
Second Question:
In the video sequence upon detecting The corners I need to play another video inside the rectangle. I was trying to do this using a single thread but it lead to a lot of lag and jerks. What can I possibly do to improve my processing speed. Do I need to use multiple threads for each video. One video is from the webcam while the other is from the hard-drive.
Here is what I did for one of previous projects.
Find all contours in your picture and approximate each with 4 corner shape
Find right rectangle with your own condition such as rectangle with area > 1000000
(optional) you will notice that your rectangle is not real rectangle because of 3D world. You might want to do perspective transformation to get correct rectangle
Paint green or whatever texture on the found rectangle since you already have 4 corners from above
As for jerky playing, you might want to use not only multithreading with GPU but also encryption to improve speed.

How to stablize the circle from video stream using opencv?

I've started using OpenCV few days back, My aim is to detect a circle and its centre, I've used hough transform, I'm using a webcam of resolution 640x480, It is working but the circle keeps on changing its position, to better explain it I posted a screen grab on youtube https://www.youtube.com/watch?v=6EGePHkGrok
Here is the code http://pastebin.com/zRG4Yfzy ,yes I know its a bit messy.
First the full video is shown, when the camera stabilizes I press ESC, then the processing begins on the ROI 250x250.
I've added few trackbars to change to parameters of hough transform and amount of blur, changing the blur amount doesn't solve the problem
How to stabilize the circle? Also the camera will not move so no tracking is needed.
Or should I adopt a completely new method of doing this?
According to my understanding I need to apply some sort of filter.
The object has many circular contours, but all have the same centre, so any of the circular contour is detected its fine.
PS:I'm no Image Processing expert, I patched up the code from various sites and books
Hough transforms are known to be error prone.
For your case, you may find contours in your image and filter them by their circularity.
1- grayscale
2- low pass filter (gaussian blur)
3- canny edge detection
4- find contours and list their areas.
5- draw min enclosing circles to your contours.
6- select the contour which has min enclosing circle area closest to contour area.
7- find center of mass of the contour using moments F3 type "mass centers"

Opencv C++ finding movement in a thresholded image

I am using openCv with C++ and I am trying to find a moving ball under different lighting conditions. So far I am able to filter an image by thresholding it using HSV color space. The problem with this is that it will pick up other object that have a similar color. It is very tedious to figure out the exact hsv range everytime there is a ball with different color/background.
Is there a way for me to apply any filter on the thresholded binary image to detect only the objects that are moving? This way I will only find the ball and not other objects since they are usually stationary.
Thank you,
Varun
Simplest approach would be frame differencing / background learning in an image sequence.
frame differencing: substract two successive frames, the result is the moving part (you will probably only get the edges of moving objects)
background learning: e.g. build an average over 50 frames, this would be your learned background, then substract the current frame, again the difference is the moving part