Ask Your Question

FShiwani's profile - activity

2017-01-07 16:58:03 -0600 asked a question Contours altering threshold image.

Hi,

I'm trying to code some hand detection that will tell me how many fingers a user is holding up. I'm new to openCV. I'm running OpenCV 3 on Visual Studio 2015. At the moment I have managed to get the threshold image to detect my hand, however I can't seem to get it to draw a contour around it even though it is clearly the largest contour available. I found some decent HSV values that seemed to work well, however I can't get the largest contour part to work at all. I've tried to use findContours on my threshold image. When I run my code with the contours section, it works perfectly, I can clearly see my hand being the largest white contour on the image. However as soon as I add my largest contour code in order to isolate my hand, the threshold doesn't do anything that it did before. I'm getting useless results. Here is the code:

#include "opencv2\opencv.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(int argv, char** argc) {

    Mat src;
    Mat hsv;
    Mat threshold;
    VideoCapture capture;

    capture.open(0);
    while (true) {
        capture >> src;
        cvtColor(src, hsv, COLOR_BGR2HSV);
        inRange(hsv, Scalar(0, 10, 60), Scalar(20, 150, 255), threshold);
        int dilation_size = 3;
        Mat element = getStructuringElement(MORPH_ELLIPSE, Size(2 * dilation_size + 1, 2 * dilation_size + 1), Point(dilation_size, dilation_size));
        //medianBlur(hsv, hsv, 5);
        //dilate(hsv, hsv, element);

        //LARGEST CONTOUR SECTION
        std::vector<std::vector<Point> > contours;
        findContours(threshold, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
        int largest_contour_area = 0;
        int largest_contour_area_index = 1;
        for (int i = 0; i < contours.size(); i++) {

            double contour_area = contourArea(contours[i], false);

            if (contour_area > largest_contour_area) {
                largest_contour_area = contour_area;
                largest_contour_area_index = i;
            }

        }
        drawContours(src, contours, largest_contour_area_index, (0, 255, 0), 1);

        //Displaying results
        imshow("src", src);
        imshow("Threshold", threshold);
        waitKey(10);
    }
    return 0;
}
2017-01-07 16:53:03 -0600 commented answer Hand detection not working.

Ah. That seems to have fixed it. I appreciate the response.

2017-01-05 18:13:07 -0600 commented question Hand detection not working.

@LBerger I tried adjusting my code to match what you have there and it is displaying the same thing.It isn't detecting my hand at all. It keeps wanting to detect random parts of the wall. Do you know any approximate HSV min and max values that I should use to detect certain skin colours? Maybe my HSV values aren't done correctly. I do remember the values that worked perfectly once but aren't working anymore. Currently I am in front of a white wall, with nothing but my hand and using values of H(0,180), S(0,220),V(190,255). Where the first value is the MIN value and the second one is the max value.

2017-01-05 08:47:39 -0600 commented answer Hand detection not working.

I appreciate the response. The code you posted above builds perfectly fine, however as soon as I run it I get the following errors:

The thread 0x2d2c has exited with code -1 (0xffffffff).
The thread 0x4bf8 has exited with code -1 (0xffffffff).
The thread 0x3f30 has exited with code -1 (0xffffffff).
The program '[13516] FingerDetection.exe' has exited with code -1 (0xffffffff).
2017-01-02 19:19:40 -0600 asked a question Hand detection not working.

I'm using OpenCV3 with Visual Studio 2015 in C++. I cannot seem to get the program to detect my hand only. It creates a contour of my hand and the surrounding wall when I don't make it only display the largest area contour. However when I force it to find and display only the largest area contour, it completely ignores my hand. I've tried it in several background cases including a white wall with just my hand. My code is as follows:

#include "opencv2\opencv.hpp"

using namespace cv;

void on_trackbar(int, void*) {
    // Dummy function
}

int main(int argv, char** argc) {
    Mat frame;
    Mat grayFrame;
    Mat hsvFrame;
    Mat thesholdFrame;
    VideoCapture capture;

    //Trackbar variables (H,S,V)
    int H_MIN = 0;
    int H_MAX = 180;
    int S_MIN = 0;
    int S_MAX = 255;
    int V_MIN = 0;
    int V_MAX = 255;




    namedWindow("trackbar", 0);
    //create memory to store trackbar name on window
    char TrackbarName[50];
    sprintf(TrackbarName, "H_MIN");
    sprintf(TrackbarName, "H_MAX");
    sprintf(TrackbarName, "S_MIN");
    sprintf(TrackbarName, "S_MAX");
    sprintf(TrackbarName, "V_MIN");
    sprintf(TrackbarName, "V_MAX");


    createTrackbar("H_MIN", "trackbar", &H_MIN, H_MAX, on_trackbar);
    createTrackbar("H_MAX", "trackbar", &H_MAX, H_MAX, on_trackbar);
    createTrackbar("S_MIN", "trackbar", &S_MIN, S_MAX, on_trackbar);
    createTrackbar("S_MAX", "trackbar", &S_MAX, S_MAX, on_trackbar);
    createTrackbar("V_MIN", "trackbar", &V_MIN, V_MAX, on_trackbar);
    createTrackbar("V_MAX", "trackbar", &V_MAX, V_MAX, on_trackbar);



    capture.open(0);
    std::vector<std::vector<cv::Point> > contours;


    while (true){
        capture >> frame;
        waitKey(10);

        cvtColor(frame, hsvFrame, COLOR_BGR2HSV);
        //imshow("HSV", hsvFrame);

        inRange(hsvFrame, Scalar(H_MIN, S_MIN, V_MIN), Scalar(H_MAX, S_MAX, V_MAX), thesholdFrame);
        int dilation_size = 3;
        Mat element = getStructuringElement(MORPH_ELLIPSE, Size(2 * dilation_size + 1, 2 * dilation_size + 1), Point(dilation_size, dilation_size));
        //medianBlur(hsvFrame, hsvFrame, 5);
        //dilate(hsvFrame, hsvFrame, element);
        findContours(thesholdFrame, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

        int largest_contour_area = 0;
        int largest_contour_area_index = 1;
        for (int i = 0; i < contours.size(); i++) {

            double contour_area = contourArea(contours[i], false);

            if (contour_area > largest_contour_area) {
                largest_contour_area = contour_area;
                largest_contour_area_index = i;
            }

        }

        drawContours(frame, contours, largest_contour_area_index, (0, 255, 0), 1);
        //drawContours(frame, contours, -1, (0, 255, 0), 3);
        putText(frame, "NO DETECTION", Point(25, 40), 2, 1, CV_RGB(255, 255, 0), 1, 8, false);

        imshow("Threshold", thesholdFrame);
        //imshow("HSV", hsvFrame);
        imshow("Camera", frame);
    }

}

Can any of you try and run this to see if it works? Keep in mind that I am new to OpenCV.

2016-12-01 22:08:37 -0600 asked a question OpenCV3 Visual Studio set up issues

Hi,

I am completely new to openCV and Visual Studio. I had a look online at it seemed most people with Visual Studio 2015 were using OpenCV3 which is what I opted for. I followed a guide - https://www.youtube.com/watch?v=l_4fN...

I set up everything according to that and ran the same code he is running. It runs, a CMD pops up then closes with the following error messages in the VS output:

 'FingerDetection.exe' (Win32): Loaded 'C:\Users\fshiw\Documents\Visual Studio 2015\Projects\FingerDetection\x64\Debug\FingerDetection.exe'. Symbols loaded.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Program Files (x86)\opencv\build\x64\vc14\bin\opencv_world310d.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\comdlg32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.14393.447_none_0d5aa7fbb6d35646\comctl32.dll'. Cannot find or open the PDB file.
'FingerDetection.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll ...
(more)