本代码可用于获取物体的坐标偏移量,旋转角度。
//if(thresholdValue)
{
Mat src = Mat(imHeight,imWidth,CV_8U,pImageBuffer);
Mat mat;
src.copyTo(mat);
threshold(mat,mat,thresholdValue,1,CV_THRESH_BINARY);
//寻找最外层轮廓
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(mat,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_NONE,Point());
Mat imageContours=Mat::zeros(mat.size(),CV_8UC1); //最小外接矩形画布
int toatal = 0;
int index = 0;
for(int i=0;i<contours.size();i++)
{