Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Pedestrian direction with cv::calcGlobalOrientation

I'm trying detect moving direction of pedestrian by different way. One of a way is using motion gradient, 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

Pedestrian direction with cv::calcGlobalOrientation

I'm trying detect moving direction of pedestrian by different way. One of a way is using motion gradient, 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, 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

Pedestrian direction with cv::calcGlobalOrientation

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, 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) 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