日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

opencv圖像匹配

 昵稱20590214 2014-12-30
//圖像配準(zhǔn)
void Match::image_match()
{
IplImage *image;
IplImage *image_model,*image_result,*image_rotation,*model_rotation,*match_result;
image=cvLoadImage("oil.jpg",0);
CvSize size;
size.height=image->height/2;
size.width=image->width/2;
image_model=cvCreateImage(size,image->depth,image->nChannels);
//cvResize(image,image_model,CV_INTER_LINEAR);
cvSetImageROI(image,cvRect(100,110,size.width,size.height));//截圖
cvCopy(image,image_model,NULL);//復(fù)制圖片
cvResetImageROI(image);//還原截圖還原截圖
CvPoint pp1, pp2;
    CvPoint leftup,rightup,leftdown,rightdown; //定義匹配結(jié)果的4個(gè)點(diǎn)
double minVal, maxVal;
int resultW,resultH; //匹配結(jié)果的長寬
image_result=cvCloneImage(image);
image_rotation=cvCloneImage(image);
//image_rotation=cvCreateImage(cvSize(image->height,image->width), IPL_DEPTH_32F, 1);
model_rotation=cvCloneImage(image_model);
    //model_rotation=cvCreateImage(cvSize(image_model->height,image_model->width), IPL_DEPTH_32F, 1);
//lefttop
resultW=image->width-image_model->width+1;
resultH=image->height-image_model->height+1;
    match_result=cvCreateImage(cvSize(resultW,resultH), IPL_DEPTH_32F,1);
cvMatchTemplate(image, image_model,match_result, CV_TM_CCOEFF); 
cvMinMaxLoc(match_result,&minVal,&maxVal,&pp1,&pp2);
leftup.x=pp2.x;
leftup.y=pp2.y;
//righttop
Globle g;
g.ImageRotation(image,image_rotation,90); //把圖像逆時(shí)針旋轉(zhuǎn)90度
g.ImageRotation(image_model,model_rotation,90); //把模板逆時(shí)針旋轉(zhuǎn)90度
resultW=image_rotation->width-model_rotation->width+1;
resultH=image_rotation->height-model_rotation->height+1;
    cvReleaseImage(&match_result);  //釋放第一次匹配結(jié)果
match_result=cvCreateImage(cvSize(resultW,resultH), IPL_DEPTH_32F, 1);
cvMatchTemplate(image_rotation, model_rotation,match_result, CV_TM_CCOEFF); 
cvMinMaxLoc(match_result,&minVal,&maxVal,&pp1,&pp2);
rightup.x=image_rotation->width-pp2.y-45;
rightup.y=pp2.x-45;
//rightdown
g.ImageRotation(image,image_rotation,180); //把圖像逆時(shí)針旋轉(zhuǎn)90度
g.ImageRotation(image_model,model_rotation,180); //把模板逆時(shí)針旋轉(zhuǎn)90度
resultW=image_rotation->width-model_rotation->width+1;
resultH=image_rotation->height-model_rotation->height+1;
    cvReleaseImage(&match_result);  //釋放第二次匹配結(jié)果
match_result=cvCreateImage(cvSize(resultW,resultH), IPL_DEPTH_32F, 1);
cvMatchTemplate(image_rotation, model_rotation,match_result, CV_TM_CCOEFF); 
cvMinMaxLoc(match_result,  &minVal, &maxVal, &pp1, &pp2);
rightdown.x=image_rotation->width-pp2.x;
rightdown.y=image_rotation->height-pp2.y;
//leftdown
g.ImageRotation(image,image_rotation,270); //把圖像逆時(shí)針旋轉(zhuǎn)90度
g.ImageRotation(image_model,model_rotation,270); //把模板逆時(shí)針旋轉(zhuǎn)90度
resultW=image_rotation->width-model_rotation->width+1;
resultH=image_rotation->height-model_rotation->height+1;
    cvReleaseImage(&match_result);  //釋放第二次匹配結(jié)果
match_result=cvCreateImage(cvSize(resultW,resultH), IPL_DEPTH_32F, 1);
cvMatchTemplate(image_rotation, model_rotation,match_result, CV_TM_CCOEFF); 
cvMinMaxLoc(match_result,  &minVal, &maxVal, &pp1, &pp2);
leftdown.x=pp2.y+45;
leftdown.y=image_rotation->height-pp2.x+45;
cvLine(image,leftup,rightup,CV_RGB(0,0,0),2);
cvLine(image,rightup,rightdown,CV_RGB(0,0,0),2);
cvLine(image,rightdown,leftdown,CV_RGB(0,0,0),2);
cvLine(image,leftdown,leftup,CV_RGB(0,0,0),2);
//顯示
printf("width:%d,hight:%d\n",size.width,size.height);
printf("lefttop:%d,%d\n",leftup.x,leftup.y);
printf("rightup:%d,%d\n",rightup.x,rightup.y);
printf("rightdown:%d,%d\n",rightdown.x,rightdown.y);
printf("leftdown:%d,%d\n",leftdown.x,leftdown.y);
cvNamedWindow("window",1);
cvShowImage("window",image);
cvNamedWindow("window2",1);
cvShowImage("window2",image_model);
cvWaitKey(0);
cvDestroyWindow("window");
cvReleaseImage(&image);
cvDestroyWindow("window2");
cvReleaseImage(&image_model);
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多