图像工作回顾之三:极线匹配

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);
}


上图:

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值