PS3 Eye Camera Color based tracking

asked 2015-09-11 11:51:24 -0600

Eisen gravatar image

Hi, I want track multiple object.I buy 4 camera licence but i cant find how can i track color based object position.I am traying change Face tracker code but when i run this code i see gray 2 screen.Where is my error ? My code is in Run Method

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This file is part of CL-EyeMulticam SDK
//
// C++ CLEyeFaceTracker Sample Application
//
// For updates and file downloads go to: http://codelaboratories.com
//
// Copyright 2008-2012 (c) Code Laboratories, Inc. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <iostream>
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

using namespace cv;
using namespace std;
// Sample camera capture and processing class
class CLEyeCameraCapture
{
    CHAR _windowName[256];
    GUID _cameraGUID;
    CLEyeCameraInstance _cam;
    CLEyeCameraColorMode _mode;
    CLEyeCameraResolution _resolution;
    float _fps;
    HANDLE _hThread;
    bool _running;
public:
    CLEyeCameraCapture(LPSTR windowName, GUID cameraGUID, CLEyeCameraColorMode mode, CLEyeCameraResolution resolution, float fps) :
    _cameraGUID(cameraGUID), _cam(NULL), _mode(mode), _resolution(resolution), _fps(fps), _running(false)
    {
        strcpy(_windowName, windowName);
    }
    bool StartCapture()
    {
        _running = true;
        cvNamedWindow(_windowName, CV_WINDOW_AUTOSIZE);
        // Start CLEye image capture thread
        _hThread = CreateThread(NULL, 0, &CLEyeCameraCapture;::CaptureThread, this, 0, 0);
        if(_hThread == NULL)
        {
            MessageBox(NULL,"Could not create capture thread","CLEyeMulticamTest", MB_ICONEXCLAMATION);
            return false;
        }
        return true;
    }
    void StopCapture()
    {
        if(!_running)    return;
        _running = false;
        WaitForSingleObject(_hThread, 1000);
        cvDestroyWindow(_windowName);
    }
    void IncrementCameraParameter(int param)
    {
        if(!_cam)    return;
        CLEyeSetCameraParameter(_cam, (CLEyeCameraParameter)param, CLEyeGetCameraParameter(_cam, (CLEyeCameraParameter)param)+10);
    }
    void DecrementCameraParameter(int param)
    {
        if(!_cam)    return;
        CLEyeSetCameraParameter(_cam, (CLEyeCameraParameter)param, CLEyeGetCameraParameter(_cam, (CLEyeCameraParameter)param)-10);
    }
    void Run()
    {
        int w, h;
        IplImage *pCapImage;
        PBYTE pCapBuffer = NULL;
        // Create camera instance
        _cam = CLEyeCreateCamera(_cameraGUID, _mode, _resolution, _fps);
        if(_cam == NULL)        return;
        // Get camera frame dimensions
        CLEyeCameraGetFrameDimensions(_cam, w, h);
        // Depending on color mode chosen, create the appropriate OpenCV image
        if(_mode == CLEYE_COLOR_PROCESSED || _mode == CLEYE_COLOR_RAW)
            pCapImage = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 4);
        else
            pCapImage = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1);

        // Set some camera parameters
        CLEyeSetCameraParameter(_cam, CLEYE_GAIN, 10);
        CLEyeSetCameraParameter(_cam, CLEYE_EXPOSURE, 511);

        // Start capturing
        CLEyeCameraStart(_cam);

        CvMemStorage* storage = cvCreateMemStorage(0);
        // Get the current app path
        char strPathName[_MAX_PATH];
        GetModuleFileName(NULL, strPathName, _MAX_PATH);
        *(strrchr(strPathName, '\\') + 1) = '\0';
        // append the xml file name
        strcat(strPathName, "haarcascade_frontalface_default.xml");
        CvHaarClassifierCascade* cascade = cvLoadHaarClassifierCascade(strPathName, cvSize(24, 24));
        IplImage* image = cvCreateImage(cvSize(pCapImage->width, pCapImage->height), IPL_DEPTH_8U, 3);
        IplImage* temp = cvCreateImage(cvSize(pCapImage->width >> 1, pCapImage->height >> 1), IPL_DEPTH_8U, 3);

        //namedWindow("kontrol",CV_WINDOW_AUTOSIZE);
        int Hmindeg=170;
        int Hmaxdeg=179;

        int Smindeg=150;
        int Smaxdeg=255;

        int Vmindeg=60;
        int Vmaxdeg=255;

        /*createTrackbar("minH","kontrol",&Hmindeg;,179);
        createTrackbar("maxH","kontrol",&Hmaxdeg;,179);

        createTrackbar("minS","kontrol",&Smindeg;,255);
        createTrackbar("maxS","kontrol",&Smaxdeg;,255);

        createTrackbar("minV","kontrol",&Vmindeg;,255);
        createTrackbar("maxV","kontrol",&Vmaxdeg;,255);*/

        int eskix = -1;
        int eskiy=-1;
        // image capturing loop
        while(_running)
        {
            cvGetImageRawData(pCapImage, &pCapBuffer;);
            CLEyeCameraGetFrame(_cam, pCapBuffer);

            cvConvertImage(pCapImage, image);

            Mat yeniframe = cvarrToMat(image);

            Mat cizgiresim = Mat::zeros(yeniframe.size(),CV_8UC3);

            Mat HSVres;
            cvtColor(yeniframe,HSVres,CV_BGR2HSV);
            Mat isres;
            inRange(HSVres,Scalar(Hmindeg,Smindeg,Vmindeg),Scalar(Hmaxdeg,Smaxdeg,Vmaxdeg),isres);

            erode(isres,isres,getStructuringElement(MORPH_ELLIPSE,Size(5,5)));
            dilate(isres,isres,getStructuringElement(MORPH_ELLIPSE,Size(5,5)));

            dilate(isres,isres,getStructuringElement(MORPH_ELLIPSE,Size(5,5)));
            erode(isres,isres,getStructuringElement(MORPH_ELLIPSE ...
(more)
edit retag flag offensive close merge delete

Comments

2
  • please try not to use anything from the outdated c-api.
  • when you use imshow(), you need a waitKey(somemillis), too (else nothing will ever get updated). not doing so is probably the reason for your gray window.
  • then, you probably have to simplify it first, to find the error.

start with throwing out all processing first, stick strictly to cv::Mat and the c++ api.

once you're able to get straight images from your cams, please have a look at the tutorials , and add your required operations back in, using modern code.

  • last but not least - if you ever need help from the internet, avoid varnames like 'yeksen', that noone but you can understand.
berak gravatar imageberak ( 2015-09-12 01:06:51 -0600 )edit

what does it mean outdated c-api ? whats new version ? have link about it.I am newbie in opencv. I am just trying learn from internet samples.

Eisen gravatar imageEisen ( 2015-09-12 06:48:11 -0600 )edit
2

anything using IplImage* will have to leave. prefer opencv's samples to sh** you find on the internet.

berak gravatar imageberak ( 2015-09-12 06:49:48 -0600 )edit

could u give an example ? how can i change this line ? IplImage* image = cvCreateImage(cvSize(pCapImage->width, pCapImage->height), IPL_DEPTH_8U, 3);

Eisen gravatar imageEisen ( 2015-09-12 15:32:50 -0600 )edit
2

you do not have to preallocate result Mat's in c++, above code is obsolete.

again, forget about your current code, and rather try the tutorials , one by one.

berak gravatar imageberak ( 2015-09-14 02:56:54 -0600 )edit