我刚刚涉足计算机视觉并试图揭开它的各种复杂性。我正在尝试使用冲浪特征检测器来增强卡尔曼滤波器。但是我不明白在使用冲浪特征在检测到的帧上构造单应性和有界矩形后如何调用和使用卡尔曼方法。在与传入帧进行比较后,我已经检测到特征并使用参考图像提取了关键点。然后我使用了flann matcher。
现在,使用卡尔曼滤波器是否可行,因为我想跟踪运动并获得预测的运动。我搜索了很多,但没有发现冲浪功能可以与卡尔曼滤波器一起使用。我得到的只是使用 cvBlobs 进行跟踪的建议。但是,理论上卡尔曼滤波器用于跟踪目的。但是,我很困惑,因为使用 surf 的基于视频的跟踪的几种实现表明 surf 本身可以用于跟踪。但我的问题是
如果卡尔曼滤波器不能与 surf 一起使用,那么我如何实现矩来获取坐标测量值,因为我需要运动预测的信息。
可以将 surf 与卡尔曼滤波器一起使用以进行跟踪,如果可以,在检测到对象并使用以下代码以矩形为边界后如何实现它。
示例:要跟踪的对象。一些帧
/* 视频中的目标检测和识别*/
int main() { Mat object = imread( "book1.png",CV_LOAD_IMAGE_GRAYSCALE );
if( !object.data ) { std::cout<< "Error reading object " << std::endl; return -1; } //Detect the keypoints using SURF Detector int minHessian = 500; SurfFeatureDetector detector( minHessian ); std::vector<KeyPoint> kp_object; detector.detect( object, kp_object ); //Calculate descriptors (feature vectors) SurfDescriptorExtractor extractor; Mat des_object; extractor.compute( object, kp_object, des_object ); FlannBasedMatcher matcher; namedWindow("Good Matches"); namedWindow("Tracking"); std::vector<Point2f> obj_corners(4); //Get the corners from the object obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( object.cols, 0 ); obj_corners[2] = cvPoint( object.cols, object.rows ); obj_corners[3] = cvPoint( 0, object.rows ); char key = 'a'; int framecount = 0; VideoCapture cap("booksvideo.avi"); for(; ;) { Mat frame; cap >> frame; imshow("Good Matches", frame); Mat des_image, img_matches; std::vector<KeyPoint> kp_image; std::vector<vector<DMatch > > matches; std::vector<DMatch > good_matches; std::vector<Point2f> obj; std::vector<Point2f> scene; std::vector<Point2f> scene_corners(4); Mat H; Mat image; //cvtColor(frame, image, CV_RGB2GRAY); detector.detect( image, kp_image ); extractor.compute( image, kp_image, des_image ); matcher.knnMatch(des_object, des_image, matches, 2); //THIS LOOP IS SENSITIVE TO SEGFAULTS for(int i = 0; i < min(des_image.rows-1,(int) matches.size()); i++) { if((matches[i][0].distance < 0.6*(matches[i][4].distance)) && ((int) matches[i].size()<=2 && (int) matches[i].size()>0)) { good_matches.push_back(matches[i][0]); } } //Draw only "good" matches drawMatches( object, kp_object, image, kp_image, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); if (good_matches.size() >= 4) { for( int i = 0; i < good_matches.size(); i++ ) { //Get the keypoints from the good matches obj.push_back( kp_object[ good_matches[i].queryIdx ].pt ); scene.push_back( kp_image[ good_matches[i].trainIdx ].pt ); } H = findHomography( obj, scene, CV_RANSAC ); perspectiveTransform( obj_corners, scene_corners, H); //Draw lines between the corners (the mapped object in the scene image ) line( img_matches, scene_corners[0] + Point2f( object.cols, 0), scene_corners[1] + Point2f( object.cols, 0), Scalar(0, 255, 0), 4 ); line( img_matches, scene_corners[1] + Point2f( object.cols, 0), scene_corners[2] + Point2f( object.cols, 0), Scalar( 0, 255, 0), 4 ); line( img_matches, scene_corners[2] + Point2f( object.cols, 0), scene_corners[3] + Point2f( object.cols, 0), Scalar( 0, 255, 0), 4 ); line( img_matches, scene_corners[3] + Point2f( object.cols, 0), scene_corners[0] + Point2f( object.cols, 0), Scalar( 0, 255, 0), 4 ); } //Show detected matches imshow( "Good Matches", img_matches ); for( int i = 0; i < good_matches.size(); i++ ) { printf( "-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); } waitKey(0);
}
返回0;
}