inline void image2text2( RECT_IMAGE* rawImage,svm_model *model,char* outbuf)
{
static int g_index=0;
RECT_IMAGE tempImage;
tempImage.init(rawImage->w,rawImage->h,NULL);
RECT_IMAGE* grayImage = &tempImage;
convert2GrayImage(rawImage,grayImage);
//writeRectImage("gray.bmp",grayImage);
std::list< std::set<XYPOINT> > connGraps;
getConnectedGraphs(grayImage,connGraps);
if ( connGraps.size()==0){
errlog(" connGraps.size() is 0");
return;
}
l_uint32 width=55;
l_uint32 height=55;
int i=0;
std::list< std::set<XYPOINT> >::iterator it = connGraps.begin();
for ( ; it != connGraps.end() ;++it)
{
RECT_IMAGE subImage;
subImage.init(width,height,NULL);
std::set<XYPOINT>& connGrap = *it;
std::vector<XYPOINT> conList(connGrap.begin(),connGrap.end());
std::vector<XYPOINT> outList/*(connGrap.begin(),connGrap.end())*/;
//去除左边缘噪点
processSubImage(rawImage,conList,outList);
l_uint32 x0=0;l_uint32 y0=0;
getOffsetPos(outList,x0,y0);
//左上角对齐
std::vector<XYPOINT>::iterator pos = outList.begin();
for ( ; pos != outList.end() ; ++pos){
l_uint32 x = pos->x;
l_uint32 y = pos->y;
l_uint32 color = rawImage->getPixel(x,y);
l_uint32 x1 = x-x0;
l_uint32 y1 = y-y0;
if (x1 >= width){
x1= width-1;
}
if( y1 >= height){
y1= height-1 ;
}
subImage.putPixel(x1,y1,color);
}
//char fn[512];
//sprintf(fn,"result\\%d.bmp",g_index++);
//writeRectImage(fn,&subImage);
//return;
//预测得到结果
svm_problem prob;
pickupFeatureDataFromRectImage(prob,&subImage);
double v = svm_predict(model, prob.x[0]);
svm_problem_release(&prob);
sprintf(outbuf+i,"%c",int(v));
i++;
}
}