Exemple #1
0
IplImage* HV_Camera::HV_QueryFrame()
{
	IplImage*  Pimage;
	HVSTATUS status = STATUS_OK;
	CString strMsg;
	

	//只定义一个缓冲区来保存图象数据
	BYTE *ppBuf[1];
	ppBuf[0] = m_pRawBuffer;
	
	status = HVSnapShot(m_hhv, ppBuf, 1);	
	if (STATUS_OK < status  || status < STATUS_INTERNAL_ERROR)
	{
		CString str="";
		str.Format("Error : 0x%08x",status);
		::MessageBox(NULL, str , "Error", MB_ICONWARNING | MB_OK);   
	}else{
			HV_VERIFY(status);
	}
		
	
	//	将原始图像数据进行Bayer转换,转换后为24位。
	//同时将原始数据进行上下翻转
	ConvertBayer2Rgb(m_pImageBuffer,m_pRawBuffer,Width,Height,ConvertType,
									m_pLutR,m_pLutG,m_pLutB,true,m_Layout);
	Pimage = Byte2IplImg(m_pImageBuffer, Width ,Height );

	return Pimage;


}
Exemple #2
0
void CMainFrame::Scan()
{    
	 CView *pView		= GetActiveView();		//获取当前VIEW视图
     CDC *pDC			= pView->GetDC();		//得到VIEW的DC
    
	 CString cs;
     cs.Format("%d",Scan_num+1);
     pDC->TextOut(0,Height/2,cs,cs.GetLength());
     pView->ReleaseDC(pDC);
     


     int i,k;
	 unsigned char MAX=0;
	 int MAX_i=0;
	 unsigned char seq[3];
	 float  peak;
	 float  distance;
	 float  Phi;
	 //float  Theta;
	 float Z;
	 float L1,L2,L3,L4;
	 float r;
	 uchar* ptr;

	 HVSTATUS status =STATUS_OK;
	/********采集单帧图像**********/
    unsigned char *ppbuffer[1];
	ppbuffer[0]=m_pRawBuffer;
   	

	status =HVSnapShot(m_hhv,ppbuffer,1);

    HV_VERIFY(status);

	/********显示当前帧************/
	OnSnapChange(NULL,NULL);

    
	//生成支持OPENCV的IPLIMAGE数据结构,并使用相机采集的图像数据初始化//
    CvSize cvSize;
	cvSize.width = Width;
 	cvSize.height = Height;
 	
	
	IplImage *iplImage = cvCreateImageHeader(cvSize,IPL_DEPTH_8U,3);
 	cvSetData(iplImage,m_pImageBuffer,Width*3);
 	
	//申请灰度空间,将BGR格式转化为灰度数据
 	IplImage *iplgray = cvCreateImage(cvGetSize(iplImage),IPL_DEPTH_8U,1);

 	cvCvtColor(iplImage,iplgray,CV_BGR2GRAY);
    
	for(k=0;k<Height;k++)
	{
		ptr=(uchar*)(iplgray->imageData+k*iplgray->widthStep);

        for(i=0;i<Width;i++)


     	for(i=0;i<Width;i++)
		{
	    	if( ptr[i]>=MAX)
			{
			  MAX=ptr[i];
			  MAX_i=i;
			}
		}
        
		if(MAX<=50)
		{
           Scan_result[Scan_num][k].X=0;
           Scan_result[Scan_num][k].Y=0;
		   Scan_result[Scan_num][k].Z=0;
		   continue;
		}

		if(MAX_i<=1)
		   seq[2]=0;
		else 
		  seq[2]=ptr[MAX_i-1];

		seq[1]=ptr[MAX_i];
		
		if(MAX_i>=Width)
		  seq[0]=0;
		else
		  seq[0]=ptr[MAX_i+1];


		//peak=1/2*(log(seq[0])-log(seq[2]))/(log(seq[0])-2*log(seq[1])+log(seq[2]))+Width-MAX_i;
              peak=(seq[2]-seq[0])/(seq[0]+seq[1]+seq[2])+Width-MAX_i;
           //peak=(2*ptr[MAX_i-2]+ptr[MAX_i-1]-ptr[MAX_i+1]-2*ptr[MAX_i+2])/(ptr[MAX_i+2]+ptr[MAX_i+1]+ptr[MAX_i]+ptr[MAX_i-1]+ptr[MAX_i-2])+Width-MAX_i;
 

        
        /************************计算某行扫描结果*****************************************/

        distance=FS/(PIX_SIZE*peak+ PIX_OFF)+DIST_OFF; 
		if(distance>1800)
		{
           Scan_result[Scan_num][k].X=0;
           Scan_result[Scan_num][k].Y=0;
		   Scan_result[Scan_num][k].Z=0;
		   continue;
		}
		//Theta=atan((k-Height/2)*PIX_SIZE/f);
        Z=(distance-DIST_OFF)*(Height/2-k)*PIX_SIZE/f;
        L1=sqrt(distance*distance+Z*Z);
        

		L3=  distance*tan(PI/2- LaserAngle);
		L2=  sqrt(L1*L1+L3*L3);
		L4=  sqrt(L3*L3+distance*distance);

		r=   sqrt( (L3-rotation_r)*(L3-rotation_r)+distance*distance);

        Phi=Scan_num*Scan_step+PI/2-acos( (rotation_r*rotation_r+r*r-L4*L4)/2.0f/rotation_r/r);


		Scan_result[Scan_num][k].X=r*cos(Phi);
        Scan_result[Scan_num][k].Y=r*sin(Phi);
		Scan_result[Scan_num][k].Z=Z;
		/****************************************************************************/
	
	}
 


	cvReleaseImage(&iplgray);
  /************如果扫描完成,关闭串口,并输出数据********/
	if(Scan_num==Scan_total-1)
	{  
	   MessageBox("扫描完成");
	   Scan_num=0;
	   OnBtnSend('2');
       //OnBtnSend('2');
	   sio_close(Port); //关闭串口
	   /*************数据输出**************/
	   char* fileName=dataout;
	   CString strtemp;

       CFile file;
	   CFileException fileException;
	   if(!file.Open(fileName,CFile::modeCreate | CFile::modeWrite, &fileException))
	   {
		   CString errorInfo;
		   errorInfo.Format("不能打开文件%s,错误:%u\n",fileName,fileException.m_cause);
		   MessageBox(errorInfo,"错误",MB_OK|MB_ICONERROR);
		   return;
	   }

	   for(i=0;i<Scan_total;i++)
		   for(k=0;k<Height;k++)
		   {
			   if(Scan_result[i][k].X==0 & Scan_result[i][k].Y==0 & Scan_result[i][k].Z==0)
                  continue;
			   else
			   { strtemp.Format("%.3f, %.3f, %.3f\r\n\r\n",Scan_result[i][k].X,Scan_result[i][k].Y,Scan_result[i][k].Z);
				   file.Write(strtemp,strtemp.GetLength());
			   }
				  
		   }
	    file.Close();
		MessageBox("已成功输出数据","信息",MB_OK|MB_ICONINFORMATION);  

	   return;
	}
  /**********扫描未完成,发送串口指令***********/
    else
    { 
		OnBtnSend('1');
		//OnBtnSend('1');
		Scan_num=Scan_num+1;
	
    }  
 
}
void DaHengCamera::daHengSnapShot(int camNo)
{
    (camNo==1)?(HVSnapShot(m_hhv_1, &m_pRawBuffer_1, 1)):(HVSnapShot(m_hhv_2, &m_pRawBuffer_2, 1));
}