Home > Back-end >  Combination of KCF algorithm and the problems encountered in the process of image registration algor
Combination of KCF algorithm and the problems encountered in the process of image registration algor

Time:10-28

Code and operation result is as follows, don't know why imshow there is no output, when debugging, also didn't find any questions, just contact this side is white, wish everyone a great god
# include & lt; Iostream>
# include & lt; Algorithm>

# include & lt; Opencv2/core/core. Hpp>
# include & lt; Opencv2 highgui/highgui. Hpp>
#include
#include
#include
# include "math. H"
#include
H # include "Windows."
# include "kcftracker. HPP
"
//# pragma comment (lib, "opencv_world310d. Lib")

using namespace std;
Using the namespace CV;
Using the namespace xfeatures2d;




Int main (int arg c, char * argv []) {

//if (arg c & gt; 5) return - 1;

Bool HOG=true;
Bool FIXEDWINDOW=false;
Bool MULTISCALE=true;
Bool SILENT=true;
Bool LAB=false;

//for (int I=0; i //if (STRCMP (argv [I], "hog")==0)
//HOG=true;
//if (STRCMP (argv [I], "fixed_window")==0)
//FIXEDWINDOW=true;
//if (STRCMP (argv [I], "singlescale")==0)
//MULTISCALE=false;
//if (STRCMP (argv [I], "show")==0)
//SILENT=false;
//if (STRCMP (argv [I], "lab")==0) {
//LAB=true;
//HOG=true;
//}
//if (STRCMP (argv [I], "gray")==0)
//HOG=false;
//}

//Create KCFTracker object
KCFTracker tracker (HOG, FIXEDWINDOW, MULTISCALE, LAB);

//set the input video
STD: : string video="E:/shiyan. Mp4"; E://data////"trackingData//tracking_clip mp4"; E:////"dudek. Webm";//argv [1].
VideoCapture cap (video);//open video file

Mat frame;
Mat src1, src2, DST;

//get bounding box
Cap & gt;> Frame;//read the first frame of video

Mat src11=imread (" D:/tupian1. JPG ", IMREAD_REDUCED_COLOR_4);
Mat src21=frame;

CvtColor (src11, src1, CV_BGR2GRAY);
CvtColor (src21, src2, CV_BGR2GRAY);
Clock_t start and finish;
Double totaltime.
Start=clock ();
Ptr The orb=SIFT: : create ();//set the image registration algorithm
//the begin
Vector Keypoints1 keypoints2;
Mat descriptors1 descriptors2;
The orb - & gt; DetectAndCompute (src1, Mat (), keypoints1 descriptors1);
The orb - & gt; DetectAndCompute (src2, Mat (), keypoints2 descriptors2);

BFMatcher matcher.//set the similarity evaluation parameter
Vector Matches1;

The matcher. Match (descriptors1 descriptors2, matches1);

Sort (matches1. The begin (), matches1 end ());

Vector QueryIdxs (matches1. The size ()), trainIdxs (matches1. The size ());
For (size_t I=0; i {
QueryIdxs [I]=matches1 [I] queryIdx;
TrainIdxs [I]=matches1 [I] trainIdx;
}

Mat H12;//transformation matrix
VectorVectorFloat ransacReprojThreshold=3;//reject threshold

H12=findHomography (Mat (points1), Mat (points2), RHO, 3);//set to remove false matching algorithm (RANSAC/PROSAC (RHO))
/* cout & lt; <"\ n the program running time for" & lt;
Vector MatchesMask (matches1. The size (), 0).
Mat points1t;
PerspectiveTransform (Mat (points1), points1t, H12);//transmission transform
For (size_t I=0; i '{
If (norm (points2 [I] - points1t. At{
MatchesMask [I]=1;
}
}
//drawMatches (src1, keypoints1, src2, keypoints2, matches1, match_img2, Scalar: : (1), all Scalar: : (1), all matchesMask);

The vector & lt; KeyPoint> RR_KP1 RR_KP2;
Vector RR_matches;
Int mask_sum=0;

Double sumloss=0;
For (size_t I=0; i {
If (matchesMask [I]!=0)
{
Sumloss +=norm (points2 [I] - points1t. AtMask_sum + +;
}
}
Sumloss=sumloss/(mask_sum - 1);

//cout & lt; <"Rmse=" & lt;
WaitKey (0);

int count=0;
For (size_t I=0; i {
If (matchesMask [I]==1)
{
count++;
}
}
//cout & lt; <"Remove the false match after match point" & lt;
STD: : vectorObj_corners [0]=cvPoint (0, 0);
Obj_corners [1]=cvPoint (src1. Cols, 0);
Obj_corners [2]=cvPoint (src1. Cols, src1. Rows);
Obj_corners [3]=cvPoint (0, src1. Rows);

STD: : vectorPerspectiveTransform (obj_corners scene_corners, H12);//by transmission transformation to find objects
Scene_corners line (src21, scene_corners [0], [1], the Scalar (0, 0, 255), 2);
, scene_corners line (src21, scene_corners [1] [2], the Scalar (0, 0, 255), 2);
Scene_corners line (src21, scene_corners [2], [3], the Scalar (0, 0, 255), 2);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related