コード例 #1
0
void CScanImage::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bCameraActive&&bWindowMoved==TRUE)
		{
			okSetToWndRect(hBoard,m_image);//设置Picture控件为目标体
			okCaptureTo(hBoard,SCREEN,0,0);//恢复连续采样
			bWindowMoved=FALSE;
		}
	CDialog::OnLButtonDown(nFlags, point);
}
コード例 #2
0
void CScanImage::OnMove(int x, int y) 
{
	CDialog::OnMove(x, y);
	if(bCameraActive&&bWindowMoved)
	{
		okSetToWndRect(hBoard,m_image);//设置Picture控件为目标体
		okCaptureTo(hBoard,SCREEN,0,0);//恢复连续采样
	}
	// TODO: Add your message handler code here
	
}
コード例 #3
0
void VideoToGet::run()
{
    _init = false;
    _stop = false;
    bool success = start_camera();

    _init=true;
    if (!success)
    {
        return;
    }


    LPBYTE	lpbuf;

    short	height,width;
    long	stride;
    long no=0;
    int _is_new_picture;
    lpbuf=(unsigned char *)okGetTargetInfo(hBoard,BUFFER,no,&width,&height,&stride);

    //int i=0;ceshi
//    QTime t;
//    t.start();
//    cv::Mat _buf_image(576,768,CV_8UC3);
//    int _i=0;
    while(!_stop)
    {
        while(_can_capture)
        {
            qDebug()<<"capture"<<timer.currentTime();

            _is_new_picture=okCaptureTo(hBoard,BUFFER,0,0);//第四个参数是0;代表连续采集,即是实时采集,无回调支持

            if(_is_new_picture>0)
            {
                emit new_image(lpbuf);
                _is_new_picture=0;
                _can_capture=false;

            }
        }

    }

}
コード例 #4
0
void CScanImage::OnButton1() 
{
	// TODO: Add your control notification handler code here
	okCaptureTo(hBoard,BUFFER,0,CROSS_CAPTURE_NUM);//采集一幅图像
	okGetCaptureStatus(hBoard,1);//等待采集完毕
	long lBitNumber=CAMERA_WIDTH*CAMERA_HEIGHT;//单幅图像数据所需空间大小
	cData=new unsigned char[lBitNumber]; //开辟自用图像数据区
	memcpy(cData, lpLinear, lBitNumber); //将BUFFER中数据拷贝到开辟的自由图像数据区
	int nCenterX,nCenterY;
	int nWidth=CAMERA_WIDTH;
	int nHeight=CAMERA_HEIGHT;
	
	FindCenter(cData,nCenterX,nCenterY,nWidth,nHeight);//在当前的图像数据中,寻找亮度极大值点(作为十字叉中心)
	delete cData;

	m_nXPos=nCenterX;
	m_nYPos=nCenterY;
	
	Invalidate();
}
コード例 #5
0
BOOL CScanImage::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	bWindowMoved=FALSE;
	pComboBox1=(CComboBox*)GetDlgItem(IDC_COMBO1);//初始化组合框类指针成员
	pComboBox2=(CComboBox*)GetDlgItem(IDC_COMBO2);//初始化组合框类指针成员

	CMainFrame* MainFramePoint=(CMainFrame*)((CFrameWnd*)AfxGetApp()->m_pMainWnd);
	hBoard=MainFramePoint->getHANDLEOK();//获得相机句柄
	lpLinear=MainFramePoint->getLPBYTEOK();//获得相机数据空间指针
	okSetToWndRect(hBoard,m_image);//设置相机输出对象
	if(!okCaptureTo(hBoard,SCREEN,0,0))//启动相机(连续拍摄模式)
		sprintf(cItemText,"Could not capture the camera image!");
	else
		bCameraActive=TRUE;//设置相机为工作状态
	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
コード例 #6
0
void CScanImage::OnButton2() 
{
	// TODO: Add your control notification handler code here
	okCaptureTo(hBoard,BUFFER,0,CROSS_CAPTURE_NUM);//采集一幅图像
	okGetCaptureStatus(hBoard,1);//等待采集结束
	int nWidth=CAMERA_WIDTH;
	int nHeight=CAMERA_HEIGHT;
	long lBitNumber=nWidth*nHeight;//单幅图像所需数据空间大小
	BITMAPFILEHEADER fhead;
	LPBITMAPINFOHEADER lpDIBInfo;
	BYTE *lpBmp;

	eDIB=GlobalAlloc(GMEM_MOVEABLE, sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+sizeof(unsigned char)*lBitNumber);//开辟位图空间
	lpBmp=(BYTE*)GlobalLock(eDIB);
	//以下写文件头	
	lpDIBInfo=(LPBITMAPINFOHEADER)lpBmp;
	lpDIBInfo->biSize = sizeof(BITMAPINFOHEADER);
	lpDIBInfo->biWidth = nWidth;
	lpDIBInfo->biHeight = nHeight;
	lpDIBInfo->biPlanes = 1;
	lpDIBInfo->biBitCount = 8;
	lpDIBInfo->biCompression = 0;
	lpDIBInfo->biSizeImage = (lpDIBInfo->biWidth)*(lpDIBInfo->biHeight);
	lpDIBInfo->biXPelsPerMeter = 0;
	lpDIBInfo->biYPelsPerMeter = 0;
	lpDIBInfo->biClrUsed = 0;
	lpDIBInfo->biClrImportant = 0;
	//以下写色盘
	RGBQUAD *bmiColors;
	bmiColors = (RGBQUAD*)(lpBmp+sizeof(BITMAPINFOHEADER));
	for(int i=0;i<256;i++,bmiColors++)
	{
		bmiColors->rgbBlue=i;
		bmiColors->rgbGreen=i;
		bmiColors->rgbRed=i;
		bmiColors->rgbReserved=0;
	}
	//以下写图像数据
	BYTE *lpBmpValue;
	for(i=0;i<nHeight;i++)
	{
		for(int j=0;j<nWidth;j++)
		{
			lpBmpValue=lpBmp+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+
				+ (nHeight-i-1)*nWidth+j;
			*lpBmpValue=*(lpLinear+i*nWidth+j);
			
		}
	}
	
	//写文件头
	//lpDIBInfo=(LPBITMAPINFOHEADER)lpBmp;
	fhead.bfType=256*'M'+'B';
	fhead.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)
				+256*sizeof(RGBQUAD)+lBitNumber*sizeof(unsigned char);
	fhead.bfReserved1=0;
	fhead.bfReserved2=0;
	fhead.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
	
	//保存数据
	CFileDialog browsefile(FALSE, "bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
		"Windows Bitmap Files(*.BMP)|*.bmp||", NULL);
	CString FileName;
	FILE *fp;
	if (browsefile.DoModal()==IDOK) 
	{
		FileName=browsefile.GetPathName();
		fp=fopen((LPCTSTR)FileName, "wb");
		fwrite(&fhead,1,sizeof(BITMAPFILEHEADER),fp);
		fwrite(lpBmp,1,sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)
			+lBitNumber*sizeof(unsigned char),fp);
		fclose(fp);
	}

}
コード例 #7
0
void VideoInput::run()
{
    _init = false;
    _stop = false;

    bool success = start_camera();
    _init=true;
    if (!success)
    {
        return;
    }


    LPBYTE	lpbuf;

    short	height,width;
    long	stride;
    long no=0;
    int _is_new_picture;
    lpbuf=(unsigned char *)okGetTargetInfo(hBoard,BUFFER,no,&width,&height,&stride);

    //int i=0;ceshi
//    QTime t;
//    t.start();
//    cv::Mat _buf_image(576,768,CV_8UC3);
//    int _i=0;
    while(!_stop)
    {

        _is_new_picture=okCaptureTo(hBoard,BUFFER,0,0);//第四个参数是0;代表连续采集,即是实时采集,无回调支持
        //if(_is_new_picture>0)

        //QString ii=(QString("[%1]").arg(i));


        //QString str="C:/Users/Administrator/Desktop/111/1123"+ii+".jpg";
        //LPSTR strc=(char*)str.toStdString().data();
        if(_is_new_picture>0)
        {
            //okSaveImageFile(hBoard,strc,0,BUFFER,0,1);
            emit new_image(lpbuf);
            _is_new_picture=0;

            //ceshi

//            _i++;
//            QString ii=(QString("[%1]").arg(_i));
//            QString str="C:/Users/Administrator/Desktop/111/1"+ii+".jpg";
//            cv::imwrite(str.toStdString(),_buf_image);//写文件耗时45ms


//            int bufnum=0;
//            int row_num=_buf_image.rows;
//            int col_num=_buf_image.cols*_buf_image.channels();//此循环耗时6-7ms
//            for(int j=0;j<row_num;j++){
//                unsigned char * data = _buf_image.ptr<uchar>(j);
//                for(int i=0;i<col_num;i++){
//                    data[i]=*(lpbuf+bufnum);
//                    bufnum++;
//                }
//            }
            //cv::imwrite(str.toStdString(),_buf_image);//写文件耗时45ms
           // i++;
        }

        //qDebug()<<lpbuf;
        //qDebug( "%d\n", t.elapsed() );


    }
    //qDebug( "%d\n", t.elapsed() );

}