Pedestrian direction with cv::calcGlobalOrientation

asked 2014-02-11 09:05:42 -0600

Flart gravatar image

updated 2014-02-12 01:45:53 -0600

I'm using HOG-based pedestrian detector, but reduction false-positive leads increasing false-negative, so there are many skip pedestrians. So I can't determine _direction_ only by hog detector out_rectangles, because there are several pedectrians in one frame.

So, I'm trying detect moving direction of found pedestrian by different way. One of a way is using motion gradient ( these out_rectangle to calcGlobalOrientation (see code below)), but I have unacceptably wrong result. I don't understand, why it are not handled correctly (upperbody doesn't have some changing area).

image description image description image description

code:
// ... HOG-detector
Rect r_hog // result of HOG

cvtColor(frame, frame, CV_BGR2GRAY );
cv::absdiff(frame, preframe, diff);
cv::threshold(diff,diff,30,255, THRESH_BINARY);

cv::morphologyEx( diff, diff, cv::MORPH_CLOSE, cv::Mat( 5, 5, CV_8UC1 ) );
cv::morphologyEx( diff, diff, cv::MORPH_OPEN,   cv::Mat( 5, 5, CV_8UC1 ), cv::Point( -1, -1 ), 1, cv::BORDER_CONSTANT, cv::Scalar( 0 ) );

Size imageSize = diff.size();
Mat m_motionHistoryImage( imageSize, CV_32FC1,0.0 );
Mat m_segmask( imageSize, CV_32FC1 );
Mat mask ( imageSize, CV_8UC1 );
Mat orientation( imageSize, CV_32FC1 );

double cycleTime = 0.04;
double m_maxMotionGradient( 1.5 * cycleTime );
double m_minMotionGradient = m_maxMotionGradient/10;
double m_motionHistoryDuration(7 * cycleTime ) ;
double time=clock();

double timestamp = (time - startTime) / CLOCKS_PER_SEC/1000.0;
const double min_conrour_area = 200;

cv::updateMotionHistory( diff, m_motionHistoryImage, timestamp, m_motionHistoryDuration );   
calcMotionGradient( m_motionHistoryImage, mask, orientation, m_minMotionGradient, m_maxMotionGradient, 3 );

Rect r_without_legs = Rect(r_hog.x,r_hog.y, r_hog.width, r_hog.height/2);

double angle = calcGlobalOrientation( orientation(r_without_legs), mask(r_without_legs), m_motionHistoryImage(r_without_legs), timestamp, m_motionHistoryDuration);
angle = 360 - angle;

// draw angle
edit retag flag offensive close merge delete

Comments

Why don't you try the HOG based pedestrian detector?

GilLevi gravatar imageGilLevi ( 2014-02-11 11:07:55 -0600 )edit

I'm using HOG based pedestrian detector, but reduction false-positive leads increasing false-negative, so there are many skip pedestrians. So I can't determine _direction_ only by hog detector out_rectangles, because there are several pedectrians in one frame. And I using these out_rectangle with calcGlobalOrientation (see code above), but it don't work correctly. ----- updated my question.

Flart gravatar imageFlart ( 2014-02-12 01:31:38 -0600 )edit