Ask Your Question

rokasma's profile - activity

2020-03-13 01:36:01 -0600 received badge  Popular Question (source)
2018-10-31 09:30:59 -0600 received badge  Notable Question (source)
2017-09-28 05:56:29 -0600 received badge  Popular Question (source)
2017-04-10 00:39:05 -0600 received badge  Popular Question (source)
2016-02-19 23:06:34 -0600 received badge  Famous Question (source)
2015-10-18 07:58:07 -0600 received badge  Famous Question (source)
2015-01-27 02:38:28 -0600 received badge  Notable Question (source)
2014-10-13 02:55:22 -0600 received badge  Student (source)
2014-10-08 03:33:56 -0600 received badge  Notable Question (source)
2014-08-12 02:22:32 -0600 received badge  Popular Question (source)
2014-06-17 07:18:27 -0600 received badge  Popular Question (source)
2013-11-29 04:53:55 -0600 asked a question motempl.c lag

Hi,

I have one question. For motion detection I found sample in opencv called motempl.c. But there is one problem. When i tied to test it with video, there are some lag. About 1 sec. difference between real video, and motion detection. How to solve this prolem?

Code:

#include "opencv2/video/tracking.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <time.h>
#include <stdio.h>
#include <ctype.h>

using namespace cv;

static void help(void)
{
    printf(
            "\nThis program demonstrated the use of motion templates -- basically using the gradients\n"
            "of thresholded layers of decaying frame differencing. New movements are stamped on top with floating system\n"
            "time code and motions too old are thresholded away. This is the 'motion history file'. The program reads from the camera of your choice or from\n"
            "a file. Gradients of motion history are used to detect direction of motoin etc\n"
            "Usage :\n"
            "./motempl [camera number 0-n or file name, default is camera 0]\n"
            );
}
// various tracking parameters (in seconds)
const double MHI_DURATION = 1;
const double MAX_TIME_DELTA = 0.5;
const double MIN_TIME_DELTA = 0.05;
// number of cyclic frame buffer used for motion detection
// (should, probably, depend on FPS)
const int N = 4;

// ring image buffer
IplImage **buf = 0;
int last = 0;

// temporary images
IplImage *mhi = 0; // MHI
IplImage *orient = 0; // orientation
IplImage *mask = 0; // valid orientation mask
IplImage *segmask = 0; // motion segmentation map
CvMemStorage* storage = 0; // temporary storage

// parameters:
//  img - input video frame
//  dst - resultant motion picture
//  args - optional parameters
static void  update_mhi( IplImage* img, IplImage* dst, int diff_threshold )
{
    double timestamp = (double)clock()/CLOCKS_PER_SEC; // get current time in seconds
    CvSize size = cvSize(img->width,img->height); // get current frame size
    int i, idx1 = last, idx2;
    IplImage* silh;
    CvSeq* seq;
    CvRect comp_rect;
    double count;
    double angle;
    CvPoint center;
    double magnitude;
    CvScalar color;

    // allocate images at the beginning or
    // reallocate them if the frame size is changed
    if( !mhi || mhi->width != size.width || mhi->height != size.height ) {
        if( buf == 0 ) {
            buf = (IplImage**)malloc(N*sizeof(buf[0]));
            memset( buf, 0, N*sizeof(buf[0]));
        }

        for( i = 0; i < N; i++ ) {
            cvReleaseImage( &buf[i] );
            buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
            cvZero( buf[i] );
        }
        cvReleaseImage( &mhi );
        cvReleaseImage( &orient );
        cvReleaseImage( &segmask );
        cvReleaseImage( &mask );

        mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
        cvZero( mhi ); // clear MHI at the beginning
        orient = cvCreateImage( size, IPL_DEPTH_32F, 1 );
        segmask = cvCreateImage( size, IPL_DEPTH_32F, 1 );
        mask = cvCreateImage( size, IPL_DEPTH_8U, 1 );
    }

    cvCvtColor( img, buf[last], CV_BGR2GRAY ); // convert frame to grayscale

    idx2 = (last + 1) % N; // index of (last - (N-1))th frame
    last = idx2;

    silh = buf[idx2];
    cvAbsDiff( buf[idx1], buf[idx2], silh ); // get difference between frames

    cvThreshold( silh, silh, diff_threshold, 1, CV_THRESH_BINARY ); // and threshold it
    cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ); // update MHI

    // convert MHI to blue 8u image
    cvCvtScale( mhi, mask, 255./MHI_DURATION,
                (MHI_DURATION - timestamp)*255./MHI_DURATION );
    cvZero( dst );
    cvMerge( mask, 0, 0, 0, dst );

    // calculate motion gradient orientation and valid orientation mask
    cvCalcMotionGradient( mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3 );

    if( !storage )
        storage = cvCreateMemStorage(0);
    else
        cvClearMemStorage(storage);

    // segment motion: get sequence of motion components ...
(more)
2013-11-22 05:07:34 -0600 commented question how to get direction of moving object?

hahhhahaha... I know how to track an object, but i don't know how to determine if object is comming in or out

2013-11-22 04:43:50 -0600 asked a question how to get direction of moving object?

Hi,

I am writing a code for moving objects detection, but now i want to count in/out objects. Now i can count olny how many objects cross the line. What is the best way to do that?

For detection I use frames substraction (first frame with current frame).

2013-11-13 05:55:58 -0600 commented question counting algorithm

what is the best way to count people? Now i write a code that counts by coordinates (when people cross the line it is counted)

2013-11-12 13:33:28 -0600 commented question counting algorithm

Yes, exactly

2013-11-10 12:00:58 -0600 asked a question counting algorithm

Hello,

I have people detection algorithm and it works quite good and now I want to count in/out people. What is the best way to do that?

2013-10-29 15:33:59 -0600 asked a question HOG detection from video

Hi,

When the input comes from webcam, the detection works fine. But when from video file, it works very slow (video file is playing very slow).

Here is my code:

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main (int argc, const char * argv[])
{
    VideoCapture cap("video.avi");
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);    
    if (!cap.isOpened())
        return -1;

    Mat img;
    HOGDescriptor hog;
    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

    namedWindow("video capture", CV_WINDOW_AUTOSIZE);
    while (true)
    {
        cap >> img;
        if (!img.data)
            continue;

        vector<Rect> found, found_filtered;
        hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);

        size_t i, j;
        for (i=0; i<found.size(); i++)
        {
            Rect r = found[i];
            for (j=0; j<found.size(); j++)
                if (j!=i && (r & found[j])==r)
                    break;
            if (j==found.size())
                found_filtered.push_back(r);
        }
        for (i=0; i<found_filtered.size(); i++)
        {
        Rect r = found_filtered[i];
            r.x += cvRound(r.width*0.1);
        r.width = cvRound(r.width*0.8);
        r.y += cvRound(r.height*0.06);
        r.height = cvRound(r.height*0.9);
        rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
    }
        imshow("video capture", img);
        if (waitKey(20) >= 0)
            break;
    }
    return 0;
}
2013-10-23 07:19:23 -0600 commented question svmlight problems

What do you mean windows headers?

2013-10-21 05:15:49 -0600 asked a question svmlight problems

Hello,

I am trying to train my hog algorithm and I have one problem. In svm_common.h file I have some ambiguity.

typedef struct word {
  FNUM    wnum;                /* word number */
  FVAL    weight;              /* word weight */
} WORD;

typedef struct svector {
  WORD    *words;    /* Visual Studio 2012 says that WORD is ambiguous */

Where is the problem?

2013-10-14 07:38:21 -0600 asked a question human detection with HOG. How to improve it?

Hello,

I have a code for human detection, but it works not as good as I want. I read some articles that is possible to train this detector. I was searching for hour to find some good tutorials for training. Maybe you can help me.

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main (int argc, const char * argv[])
{
    VideoCapture cap(CV_CAP_ANY);
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);    
    if (!cap.isOpened())
        return -1;

    Mat img;
    HOGDescriptor hog;
    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

    namedWindow("video capture", CV_WINDOW_AUTOSIZE);
    while (true)
    {
        cap >> img;
        if (!img.data)
            continue;

        vector<Rect> found, found_filtered;
        hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);

        size_t i, j;
        for (i=0; i<found.size(); i++)
        {
            Rect r = found[i];
            for (j=0; j<found.size(); j++)
                if (j!=i && (r & found[j])==r)
                    break;
            if (j==found.size())
                found_filtered.push_back(r);
        }
        for (i=0; i<found_filtered.size(); i++)
        {
        Rect r = found_filtered[i];
            r.x += cvRound(r.width*0.1);
        r.width = cvRound(r.width*0.8);
        r.y += cvRound(r.height*0.06);
        r.height = cvRound(r.height*0.9);
        rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
    }
        imshow("video capture", img);
        if (waitKey(20) >= 0)
            break;
    }
    return 0;
}
2013-10-07 13:24:26 -0600 asked a question hog.detectMultiScale parameters

Hello, Can anyone explaine me in simple words what these parameters:

0, Size(6,6), Size(32,32), 1.05, 2

in this function does?

do hog.detectMultiScale(img, found, 0, Size(6,6), Size(32,32), 1.05, 2);
2013-10-06 11:18:53 -0600 received badge  Critic (source)
2013-10-06 09:20:44 -0600 asked a question human recognition

Hello, I want to recognize and track human from viedo stream. What is the best way for this?

2013-10-06 08:20:50 -0600 commented question full body detection with c+

I want to recognize and detect people from video stream

2013-10-03 08:46:51 -0600 received badge  Editor (source)
2013-10-03 08:44:28 -0600 asked a question full body detection with c+

Hi, I am new with OpenCV. I wrote a code for human full body detection, but it works not very well. Sometimes when I stay infront of camera, it does not recognise me. Maybe I done some mistakes in my code. I hope You understand me.

#include "opencv2/objdetect/objdetect.hpp" 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream> 
#include <stdio.h>

using namespace std; 
using namespace cv;

/** Function Headers */ 

void detectAndDisplay( Mat frame );

/** Global variables */ 
String body_cascade_name = "haarcascade_fullbody.xml";
CascadeClassifier body_cascade; 
string window_name = "Capture - Face detection"; 
RNG rng(12345);

/** @function main */
int main( int argc, const char** argv ) 
{ 
CvCapture* capture;
Mat frame;

//-- 1. Load the cascades 

if( !body_cascade.load( body_cascade_name ) )
{ 
    printf("--(!)Error loading\n"); return -1; 
};

//-- 2. Read the video stream 
capture = cvCaptureFromCAM( -1 ); 
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 180 );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 180 );

if( capture ) 
{ 
    while( true ) 
    { 
        frame = cvQueryFrame( capture );

        //-- 3. Apply the classifier to the frame 
        if( !frame.empty() ) 
        { 
            detectAndDisplay( frame ); 
        } else { 
            printf(" --(!) No captured frame -- Break!"); 
            break; 
        }
        int c = waitKey(100); 
        if( (char)c == 'c' ) 
        { 
            break; 
        } 
    } 
} 
return 0; 
}

/** @function detectAndDisplay */ 
void detectAndDisplay( Mat frame ) 
{ 
    vector<Rect> bodys;
    Mat frame_gray;

    cvtColor( frame, frame_gray, CV_BGR2GRAY ); 
    equalizeHist( frame_gray, frame_gray );
    //-- detect body */
    body_cascade.detectMultiScale(frame_gray, bodys, 1.1, 2, 18|9, Size(3,7));
    for( int j = 0; j < bodys.size(); j++ ) 
        { 
            Point center( bodys[j].x + bodys[j].width*0.5, bodys[j].y+ + bodys[j].height*0.5 ); 
            ellipse( frame, center, Size( bodys[j].width*0.5, bodys[j].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
        } 
    imshow( window_name, frame ); 
}