예제 #1
0
// @param img: grayscaled and in RGB format (e.g. loaded from file).
void OCRer::process_image(Mat img) {
    
    /*
    if (_motion) {
        _n_imgs = 0;
        _motion = false;
    }


    if (_n_imgs == 0) {
        _average_img = img;

    } else {
        // detect motion by comparing with _last_img
        vector<uchar> status;
        vector<float> err;
        calcImageDisplacement(_last_img, img, &status, &err);

        int n = 0;
        int l = status.size();
        for (int i = 0; i < l; i++) {
            bool matched = (bool) status[i];
            if (matched) {
                n++;
            }
        }

        float fn  = (float) n;
        float fnl = (float) _last_n_features;
        float p_motion = fabs( (fn - fnl)  / fnl );          // "percentage" of motion

        _last_n_features = n;
        if (p_motion > MOTION_P_THRESHOLD)
            _motion = true;

        else if (_n_imgs < MAX_N_IMGS) {
            float alpha = 1.0f / (float) (_n_imgs + 1);
            Mat sum = Mat::zeros(img.size(), CV_32F);       // has to be CV_32F or CV_64F

            accumulate(img, sum);
            accumulate(_average_img, sum);
            sum.convertTo(_average_img, _average_img.type(), alpha);
        }
        else {
            return ;
        }
    }
    _last_img = img;
    _n_imgs++;

    OCR(_average_img);
    */
    OCR(img);
}
예제 #2
0
int __stdcall MatchCheckCode(char *szPath, char *szCode,int iThreadShod)
{
	try
	{
		IplImage *m_Source_Pic = NULL;
		m_Source_Pic = cvLoadImage(szPath);
		if (!m_Source_Pic)
		{
			strcpy(szCode,"can not open the image");
			return -2;	//找不到
		}
		IplImage * RedChannel   = cvCreateImage( cvGetSize(m_Source_Pic), 8, 1);
		IplImage * GreenChannel  = cvCreateImage( cvGetSize(m_Source_Pic), 8, 1);
		//IplImage * BlueChannel = cvCreateImage( cvGetSize(m_Source_Pic), 8, 1);
		//cvSetImageCOI(m_Source_Pic,1); 
		//cvCopy(m_Source_Pic,BlueChannel); //提取蓝色
		cvSetImageCOI(m_Source_Pic,2);
		cvCopy(m_Source_Pic,GreenChannel);  //提取绿色
		cvSetImageCOI(m_Source_Pic,3);
		cvCopy(m_Source_Pic,RedChannel); //提取红色
		cvAdd(RedChannel,GreenChannel,RedChannel);
		cvThreshold(RedChannel,RedChannel,iThreadShod,255,CV_THRESH_BINARY);
		strcat(szPath,"2.bmp");
		cvSaveImage(szPath,RedChannel);
		char *szCodeDll = OCR(szPath,-1);
		CString strRet = GetRetString(szCodeDll);
		strcpy(szCode,strRet);
		cvReleaseImage(&m_Source_Pic);
		cvReleaseImage(&RedChannel);
		cvReleaseImage(&GreenChannel);
		//cvReleaseImage(&BlueChannel);
		return 0;
	}
	catch (...)
	{
		strcpy(szCode,"excption");
	}
	return -1;
}