看了一下别的软件校对功能,大多是图片在一边,而识别结果在一边。
可以实现为逐行校对功能,即文字紧挨的就是图片。
先处理界面,增加一个校对按钮,实现处理逻辑代码:
void __fastcall TMainForm::Button_ReviewOCRClick(TObject *Sender) {
// 识别模块OcrModule:手工校对
bool checked = Button_ReviewOCR->Down;
if (checked) {
int delta = 10;
int index = 0;
for (int i = FObjects.size() - 1; i >= 0; --i) {
TCbwObject * it = FObjects[i];
TCbwTable * table = dynamic_cast<TCbwTable*>(it);
if (table) {
table->Top *= 2;
table->Zoom(1, 2, table->BeginPoint);
}
if (it->Tag == 0)
continue;
TText * text = dynamic_cast<TText*>(it);
if (!text)
continue;
TQaOcrObject * ocrObject = (TQaOcrObject*)((void*)(it->Tag));
ocrObject->RelativeObject = it;
RECT r = ocrObject->RawRect;
TCbwImage * imageObject = dynamic_cast<TCbwImage*>(NewMeta(cctImage));
imageObject->AddPoint(TCbwFloatPoint(r.left, r.top * 2));
imageObject->AddPoint(TCbwFloatPoint(r.right, r.top + r.bottom));
imageObject->Tag = int(ocrObject);
QaImage ocrImage;
FImage->Crop(r.left - r.left, r.top - r.top, r.right - r.left, r.bottom - r.top, &ocrImage);
imageObject->CopyFromImage(ocrImage);
imageObject->AutoSize = true;
FinishBuild(true);
int index = IndexOfItemInVector(FObjects, imageObject);
if (index != -1) {
FObjects.erase(FObjects.begin() + index);
FObjects.insert(FObjects.begin(), imageObject);
}
it->DragBy(imageObject->Left - it->Left, imageObject->Top + imageObject->Height - it->Top + 10, true);
++i;
}
}
else { // 恢复
cSelectedObjects->Selected = false;
for (int i = FObjects.size() - 1; i >= 0; --i) {
TCbwTable * table = dynamic_cast<TCbwTable*>(FObjects[i]);
if (table) {
table->Top /= 2;
table->Zoom(1, 0.5, table->BeginPoint);
}
TCbwImage * imageObject = dynamic_cast<TCbwImage*>(FObjects[i]);
if (!imageObject)
continue;
if (imageObject->Tag == 0)
continue;
TQaOcrObject * ocrObject = (TQaOcrObject*)((void*)(imageObject->Tag));
ocrObject->RelativeObject = NULL;
imageObject->Selected = true;
cSelectedObjects->AddObject(imageObject);
DeleteSelectedObjects();
}
Application->ProcessMessages();
}
}
原始识别结果:
校对效果:
这样,在校对时,如果发现有识别错误,可以直接双击文本进行修改。
其实这个功能需求是用户提出来的,他说如果能这样校对的话,他就会大幅提高效率。一想也是哈,直观方便些。
从实现的过程来看,逻辑很简单,不就是找到原始的图片位置,拷贝出对照图片,然后将之与识别结果进行对比排列。
编的软件还是要别人多用,自己闭门造车,只能是自己感觉良好,真正用户喜欢吗?还有待检验。