2006年完成的基于OpenCV的立体匹配与极线几何测试,VC6+OpenCV+MDI框架,匹配用SIFT,基础矩阵算法可选,默认为RANSAC。
鼠标在左或右图单击,在另一图上则画出对应的极线,蓝色表示。
当年的日志:
完成cpp版的sift移植.
2:16 2006-5-26
贴一点代码:
void CMyEpilineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMainFrame *pFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
CMyEpilineView *another;//先判断是否为左或右视图
if(this==pFrame->m_leftView)
another=pFrame->m_rightView;
else if(this==pFrame->m_rightView)
another=pFrame->m_leftView;
else
return;
if (!pFrame->m_fundamental_matrix) // 当没计算基础矩阵时
return;
cvCircle(this->GetDocument()->m_image, cvPoint(point.x,point.y), 2, CV_RGB(0,0,255), 1,8,0);
this->Invalidate(TRUE);
CvMat* points1 = cvCreateMat(2,3,CV_32F);//1个点不行!最少为3,虽然只用1个点
cvmSet(points1,0,0, point.x );
cvmSet(points1,1,0, point.y );
CvMat *correspondent_lines= cvCreateMat(3,3,CV_32F);//最少为3
if(this==pFrame->m_leftView)
cvComputeCorrespondEpilines(points1,1,pFrame->m_fundamental_matrix,correspondent_lines);
else if(this==pFrame->m_rightView)
cvComputeCorrespondEpilines(points1,2,pFrame->m_fundamental_matrix,correspondent_lines);
else
return;
//float a = correspondent_lines->data.ptr[j]+.000001;
//float b = (correspondent_lines->data.ptr+correspondent_lines->step)[j]+.000001;
//float c = (correspondent_lines->data.ptr+correspondent_lines->step*2)[j];
float a = cvmGet(correspondent_lines, 0, 0 );
float b = cvmGet(correspondent_lines, 1, 0 );
float c = cvmGet(correspondent_lines, 2, 0 );
cvReleaseMat(&points1);
cvReleaseMat(&correspondent_lines);
cvLine( another->GetDocument()->m_image, cvPoint( 0, (int)-c/b ),
cvPoint(another->GetDocument()->m_image->width,(int)(-c-a*another->GetDocument()->m_image->width)/b), CV_RGB(0,0,255),1,8,0 );
//cvCircle(image2, cvPoint( (int)cvmGet(points2,0,i),(int)cvmGet(points2,1,i) ), 2, CV_RGB(255,0,0), 1,8,0);
//printf("epiline:(0,%d)-->(%d,0)\n",(int)-c/b,(int)-c/a);
//printf("%f,%f,%f\n",a,b,c);
another->Invalidate();
// cvNamedWindow("click epiline",1);
// cvShowImage("click epiline",another->GetDocument()->m_image);
// cvWaitKey(0);
CScrollView::OnLButtonDown(nFlags, point);
}
上图: