A utility class which tracks the movement of hands. The camera image is the input.
The output can be used for hand gesture analysis.
Revisión | 2538002cbe2a604fe29bc390d48f41e98e34fb3f (tree) |
---|---|
Tiempo | 2013-07-28 22:26:44 |
Autor | tkawata <takuji.kawata@gmai...> |
Commiter | tkawata |
[NDNGestureVision] minor update for better hand tracking while camera is moving.
@@ -586,8 +586,43 @@ void NDNGestureVision::calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureV | ||
586 | 586 | { |
587 | 587 | //global move. Update background |
588 | 588 | isGlobalMove = true; |
589 | - newImage.copyTo(m_backgroundImage); | |
590 | - m_backgroundImageAge = cv::Mat::ones(m_backgroundImageAge.size(), CV_8U); | |
589 | + if (m_focusedFlowRegion.age > 0) | |
590 | + { | |
591 | + float dx = m_focusedFlowRegion.direction.x * m_focusedFlowRegion.distance; | |
592 | + float dy = m_focusedFlowRegion.direction.y * m_focusedFlowRegion.distance; | |
593 | + cv::Rect prevRect = cv::Rect(m_focusedFlowRegion.xmin - dx, m_focusedFlowRegion.ymin - dy, | |
594 | + m_focusedFlowRegion.xmax - m_focusedFlowRegion.xmin + 1, m_focusedFlowRegion.ymax - m_focusedFlowRegion.ymax + 1); | |
595 | + | |
596 | + cv::Mat tempMat(m_backgroundImage.size(), CV_8UC3); | |
597 | + cv::Mat tempROIMat(tempMat, prevRect); | |
598 | + m_backgroundImage.copyTo(tempROIMat); | |
599 | + | |
600 | + for (int y = 0; y < m_imageHeight; y++) | |
601 | + { | |
602 | + for (int x = 0; x < m_imageWidth; x++) | |
603 | + { | |
604 | + if (m_focusedFlowRegion.xmin == x) | |
605 | + { | |
606 | + int xx = x; | |
607 | + for (; xx <= m_focusedFlowRegion.xmax; xx++) | |
608 | + { | |
609 | + m_backgroundImage.at<cv::Vec3b>(y,xx) = tempROIMat.at<cv::Vec3b>(y - dy, xx - dx); | |
610 | + } | |
611 | + x = xx - 1; | |
612 | + } | |
613 | + else | |
614 | + { | |
615 | + m_backgroundImage.at<cv::Vec3b>(y,x) = newImage.at<cv::Vec3b>(y,x); | |
616 | + m_backgroundImageAge.at<uchar>(y,x) = 1; | |
617 | + } | |
618 | + } | |
619 | + } | |
620 | + } | |
621 | + else | |
622 | + { | |
623 | + newImage.copyTo(m_backgroundImage); | |
624 | + m_backgroundImageAge = cv::Mat::ones(m_backgroundImageAge.size(), CV_8U); | |
625 | + } | |
591 | 626 | } |
592 | 627 | else |
593 | 628 | { |