Exemplo n.º 1
0
IplImage* preprocessing(IplImage* imgSrc,int new_width, int new_height){
	IplImage* result;
	IplImage* scaledResult;

	CvMat data;
	CvMat dataA;
	CvRect bb;//bounding box
	CvRect bba;//boundinb box maintain aspect ratio
	
	//Find bounding box
	bb=findBB(imgSrc);
    cvSetImageROI(imgSrc,bb);
    result=cvCreateImage(cvSize(bb.width,bb.height),8,1);	
	//Get bounding box data and no with aspect ratio, the x and y can be corrupted
	//cvGetSubRect(imgSrc, &data, cvRect(bb.x, bb.y, bb.width, bb.height));
	//Create image with this data with width and height with aspect ratio 1 
	//then we get highest size betwen width and height of our bounding box
	//int size=(bb.width>bb.height)?bb.width:bb.height;
	//result=cvCreateImage( cvSize( size, size ), 8, 1 );
	//cvSet(result,CV_RGB(255,255,255),NULL);
	//Copy de data in center of image
	//int x=(int)floor((float)(size-bb.width)/2.0f);
	//int y=(int)floor((float)(size-bb.height)/2.0f);
	//cvGetSubRect(result, &dataA, cvRect(x,y,bb.width, bb.height));
	cvCopy(imgSrc, result, NULL);
	cvResetImageROI(imgSrc);
	//Scale result
	scaledResult=cvCreateImage( cvSize( new_width, new_height ), 8, 1 );
	cvResize(result, scaledResult, CV_INTER_NN);
	
	//Return processed data
	return scaledResult;
	
}
Exemplo n.º 2
0
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
 
IplImage preprocessing(IplImage* imgSrc,int new_width, int new_height) {

IplImage* result;
}

IplImage* scaledResult; CvMat data; CvMat dataA; CvRect bb;//bounding box
CvRect bba;//boundinb box maintain aspect ratio 
//Find bounding box找到边界框 
bb=findBB(imgSrc);
cvGetSubRect(imgSrc, &data, cvRect(bb.x, bb.y, bb.width, bb.height));
int size=(bb.width>bb.height)?bb.width:bb.height;
result=cvCreateImage( cvSize( size, size ), 8, 1 );
cvSet(result,CV_RGB(255,255,255),NULL);
//将图像放中间,大小归一化
int x=(int)floor((float)(size-bb.width)/2.0f); 
int y=(int)floor((float)(size-bb.height)/2.0f); 
cvGetSubRect(result, &dataA, cvRect(x,y,bb.width, bb.height));
cvCopy(&data, &dataA, NULL); //Scale result
scaledResult=cvCreateImage( cvSize( new_width, new_height ), 8, 1 ); 
cvResize(result, scaledResult, CV_INTER_NN); 
//Return processed data 
return *scaledResult;//直接返回处理后的图片
}
void basicOCR::getData()

{