Guest User

Untitled

a guest
Jul 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.33 KB | None | 0 0
  1. #include "qacheck.h"
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.h"
  4. #include "prapi.h"
  5.  
  6. #include <QObject>
  7. #include <QMessageBox>
  8. #include <QString>
  9. #include <QBitmap>
  10. #include <QPen>
  11. #include <QColor>
  12. #include <QPixmap>
  13. #include <QImage>
  14. #include <QPainter>
  15. #include <QGraphicsScene>
  16. #include <QGraphicsPixmapItem>
  17. #include <QStatusBar>
  18.  
  19.  
  20. Qacheck::Qacheck()
  21. {
  22. // InitializeComponent();
  23. QMessageBox msgBox;
  24.  
  25. try
  26. {
  27. /* Opening the PR system */
  28. StatusBar.showMessage("Opening system files");
  29.  
  30. /* Validity check */
  31. if (!pr.IsValid())
  32. {
  33. msgBox.setText("Failed to initialize!");
  34. msgBox.exec();
  35. // this.Close();
  36. return;
  37. }
  38.  
  39. /* Turn on quality check */
  40. pr.SetProperty("document/mrz_quality_check", 1);
  41.  
  42. /* Set the the range of PR_OQA_CHARDISTANCE */
  43. pr.SetProperty("document/mqc/chardistancemin", 2000); // 2000 micron or 2 mm
  44. pr.SetProperty("document/mqc/chardistancemax", 3000); // 3000 micron or 3 mm
  45.  
  46. /* Connecting to the first device */
  47. StatusBar.showMessage("Connecting to the first device");
  48. pr.UseDevice(0, PR_UMODE_FULL_CONTROL);
  49. }
  50.  
  51. catch (gxException ex)
  52. {
  53. msgBox.setText(ex.GetErrorStringA().c_str());
  54. msgBox.exec();
  55. // this.Close();
  56. }
  57. }
  58.  
  59. Qacheck::~Qacheck()
  60. {
  61. // delete ui;
  62. }
  63.  
  64. QString Qacheck::getRowProperties(gxVariant vrow)
  65. {
  66. QString s = "";
  67.  
  68. // PRV_OQCA
  69. gxVariant voqca;
  70. vrow.GetChild(voqca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
  71. s += QString(" OQCA = ") + voqca.GetASCII(voqca.GetSize()).c_str() + ";";
  72.  
  73. // PRV_WINDOWFRAME
  74. gxVariant vframe;
  75. vrow.GetChild(vframe, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
  76. gxPG4 frame = vframe.GetGxPG4();
  77. s += QString(" X1 = ") + frame.x1 + ";";
  78. s += QString(" Y1 = ") + frame.y1 + ";";
  79. s += QString(" X2 = ") + frame.x2 + ";";
  80. s += QString(" Y2 = ") + frame.y2 + ";";
  81. s += QString(" X3 = ") + frame.x3 + ";";
  82. s += QString(" Y3 = ") + frame.y3 + ";";
  83. s += QString(" X4 = ") + frame.x4 + ";";
  84. s += QString(" Y4 = ") + frame.y4 + ";";
  85.  
  86. // PRV_OQC_ROTATION
  87. gxVariant voqc_rotation;
  88. vrow.GetChild(voqc_rotation, GX_VARIANT_BY_ID, PRV_OQC_ROTATION, 0);
  89. s += QString(" ROTATION = ") + voqc_rotation.GetASCII(voqc_rotation.GetSize()).c_str() + ";";
  90.  
  91. // PRV_OQC_WIDTH
  92. gxVariant voqc_width;
  93. vrow.GetChild(voqc_width, GX_VARIANT_BY_ID, PRV_OQC_WIDTH, 0);
  94. s += QString(" WIDTH = ") + voqc_width.GetASCII(voqc_width.GetSize()).c_str() + ";";
  95.  
  96. // PRV_OQC_HANGOUT
  97. gxVariant voqc_hangout;
  98. vrow.GetChild(voqc_hangout, GX_VARIANT_BY_ID, PRV_OQC_HANGOUT, 0);
  99. s += QString(" HANGOUT = ") + voqc_hangout.GetASCII(voqc_hangout.GetSize()).c_str() + ";";
  100.  
  101. // PRV_OQC_DISTANCE
  102. gxVariant voqc_distance;
  103. vrow.GetChild(voqc_distance, GX_VARIANT_BY_ID, PRV_OQC_DISTANCE, 0);
  104. s += QString(" DISTANCE = ") + voqc_distance.GetASCII(voqc_distance.GetSize()).c_str() + ";";
  105.  
  106. return s;
  107. }
  108.  
  109. QString Qacheck::getCharProperties(gxVariant vchar)
  110. {
  111.  
  112. QString s = "";
  113.  
  114. // PRV_OQCA
  115. gxVariant voqca;
  116. vchar.GetChild(voqca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
  117. s += QString(" OQCA = ") + voqca.GetASCII(voqca.GetSize()).c_str() + ";";
  118.  
  119. // PRV_WINDOWFRAME
  120. gxVariant vframe;
  121. vchar.GetChild(vframe, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
  122. gxPG4 frame = vframe.GetGxPG4();
  123. s += QString(" X1 = ") + frame.x1 + ";";
  124. s += QString(" Y1 = ") + frame.y1 + ";";
  125. s += QString(" X2 = ") + frame.x2 + ";";
  126. s += QString(" Y2 = ") + frame.y2 + ";";
  127. s += QString(" X3 = ") + frame.x3 + ";";
  128. s += QString(" Y3 = ") + frame.y3 + ";";
  129. s += QString(" X4 = ") + frame.x4 + ";";
  130. s += QString(" Y4 = ") + frame.y4 + ";";
  131.  
  132. // PRV_OQC_ROTATION
  133. gxVariant voqc_rotation;
  134. vchar.GetChild(voqc_rotation, GX_VARIANT_BY_ID, PRV_OQC_ROTATION, 0);
  135. s += QString(" ROTATION = ") + voqc_rotation.GetASCII(voqc_rotation.GetSize()).c_str() + ";";
  136.  
  137. // PRV_OQC_HEIGHT
  138. gxVariant voqc_height;
  139. vchar.GetChild(voqc_height, GX_VARIANT_BY_ID, PRV_OQC_HEIGHT, 0);
  140. s += QString(" HEIGHT = ") + voqc_height.GetASCII(voqc_height.GetSize()).c_str() + ";";
  141.  
  142. // PRV_OQC_WIDTH
  143. gxVariant voqc_width;
  144. vchar.GetChild(voqc_width, GX_VARIANT_BY_ID, PRV_OQC_WIDTH, 0);
  145. s += QString(" WIDTH = ") + voqc_width.GetASCII(voqc_width.GetSize()).c_str() + ";";
  146.  
  147. // PRV_OQC_HANGOUT
  148. gxVariant voqc_hangout;
  149. vchar.GetChild(voqc_hangout, GX_VARIANT_BY_ID, PRV_OQC_HANGOUT, 0);
  150. s += QString(" HANGOUT = ") + voqc_hangout.GetASCII(voqc_hangout.GetSize()).c_str() + ";";
  151.  
  152. // PRV_OQC_DISTANCE
  153. gxVariant voqc_distance;
  154. vchar.GetChild(voqc_distance, GX_VARIANT_BY_ID, PRV_OQC_DISTANCE, 0);
  155. s += QString(" DISTANCE = ") + voqc_distance.GetASCII(voqc_distance.GetSize()).c_str() + ";";
  156.  
  157. // PRV_OQC_CONTRAST
  158. gxVariant voqc_contrast;
  159. vchar.GetChild(voqc_contrast, GX_VARIANT_BY_ID, PRV_OQC_CONTRAST, 0);
  160. s += QString(" CONTRAST = ") + voqc_contrast.GetASCII(voqc_contrast.GetSize()).c_str() + ";";
  161.  
  162. return s;
  163. }
  164.  
  165. QString Qacheck::getalertstr(int alert)
  166. {
  167. QString s = "";
  168.  
  169. if ((alert & PR_OQA_CHARPOSITION) != 0)
  170. s += " char position;";
  171. if ((alert & PR_OQA_CHARDISTANCE) != 0)
  172. s += " char distance;";
  173. if ((alert & PR_OQA_CHARROTATION) != 0)
  174. s += " char rotation;";
  175. if ((alert & PR_OQA_CHARSIZE) != 0)
  176. s += " char size;";
  177. if ((alert & PR_OQA_CONTRAST) != 0)
  178. s += " contrast;";
  179. if ((alert & PR_OQA_ERZ) != 0)
  180. s += " erz;";
  181. if ((alert & PR_OQA_ROWDISTANCE) != 0)
  182. s += " row distance;";
  183. if ((alert & PR_OQA_ROWPOSITION) != 0)
  184. s += " row position;";
  185. if ((alert & PR_OQA_ROWSIZE) != 0)
  186. s += " row size;";
  187. if ((alert & PR_OQA_SPARE) != 0)
  188. s += " spare;";
  189.  
  190. return s;
  191. }
  192.  
  193. void Qacheck::drawframe(gxImage fullimage, QImage *Image, gxPG4 frame, int alert)
  194. {
  195. QPainter Painter(Image);
  196. QPen pen;
  197. const int PADDING = 3;
  198. const int PENWIDTH = 2;
  199. pen.setWidth(PENWIDTH);
  200.  
  201. switch (alert)
  202. {
  203. case PR_OQA_CHARPOSITION:
  204. pen.setColor(QColor("Beige"));
  205. break;
  206. case PR_OQA_CHARDISTANCE:
  207. pen.setColor(QColor("Brown"));
  208. break;
  209. case PR_OQA_CHARROTATION:
  210. pen.setColor(QColor("BurlyWood"));
  211. break;
  212. case PR_OQA_CHARSIZE:
  213. pen.setColor(QColor("Crimson"));
  214. break;
  215. case PR_OQA_CONTRAST:
  216. pen.setColor(QColor("DarkGoldenrod"));
  217. break;
  218. case PR_OQA_ERZ:
  219. pen.setColor(QColor("DarkCyan"));
  220. break;
  221. case PR_OQA_ROWDISTANCE:
  222. pen.setColor(QColor("DarkViolet"));
  223. break;
  224. case PR_OQA_ROWPOSITION:
  225. pen.setColor(QColor("DeepPink"));
  226. break;
  227. case PR_OQA_ROWROTATION:
  228. pen.setColor(QColor("Firebrick"));
  229. break;
  230. case PR_OQA_ROWSIZE:
  231. pen.setColor(QColor("Gold"));
  232. break;
  233. case PR_OQA_SPARE:
  234. pen.setColor(QColor("Honeydew"));
  235. break;
  236. default: // alert combination
  237. pen.setColor(QColor("Red"));
  238. break;
  239. }
  240.  
  241. int sw = fullimage.xsize();
  242. int sh = fullimage.ysize(); // the source dimension
  243. int dw = Image->size().width();
  244. int dh = Image->size().height(); // the display dimension
  245.  
  246. // calculate the resolution conversion from micron to pixel
  247. double zx = (double)fullimage.xres() / 1000000;
  248. double zy = (double)fullimage.yres() / 1000000;
  249.  
  250. // map the frame to the display coordinate
  251. frame.x1 = (int)(zx * frame.x1 * dw / sw) - PADDING;
  252. frame.x2 = (int)(zx * frame.x2 * dw / sw) + PADDING;
  253. frame.x3 = (int)(zx * frame.x3 * dw / sw) + PADDING;
  254. frame.x4 = (int)(zx * frame.x4 * dw / sw) - PADDING;
  255.  
  256. frame.y1 = (int)(zy * frame.y1 * dh / sh) - PADDING;
  257. frame.y2 = (int)(zy * frame.y2 * dh / sh) - PADDING;
  258. frame.y3 = (int)(zy * frame.y3 * dh / sh) + PADDING;
  259. frame.y4 = (int)(zy * frame.y4 * dh / sh) + PADDING;
  260.  
  261. // draw the frame
  262. Painter.setPen(pen);
  263. Painter.drawLine(frame.x1, frame.y1, frame.x2, frame.y2);
  264. Painter.drawLine(frame.x2, frame.y2, frame.x3, frame.y3);
  265. Painter.drawLine(frame.x3, frame.y3, frame.x4, frame.y4);
  266. Painter.drawLine(frame.x4, frame.y4, frame.x1, frame.y1);
  267.  
  268. // g.Dispose();
  269. }
  270.  
  271. /* QImage::Format Qacheck::gx2qtformat(gxi32 gxformat)
  272. {
  273. Qimage::Format qtformat;
  274.  
  275. switch(gxformat) {
  276. case GX_UNDEF:
  277. break;
  278. case GX_GRAY:
  279. break;
  280. case RGB555:
  281. qtformat = QImage::Format_RGB555;
  282. break;
  283. case BGR555:
  284. break;
  285. case RGB565:
  286. qtformat = QImage::Format_RGB16;
  287. break;
  288. case BGR565:
  289. break;
  290. case GX_RGB:
  291. qtformat = QImage::Format_RGB888;
  292. break;
  293. case GX_BGR:
  294. break:
  295. case GX_RGBA:
  296. break
  297. case GX_BGRA:
  298. break;
  299. case GX_YUV422:
  300. break;
  301. case GX_GRAY12:
  302. qtformat = QImage::Format_RGB444;
  303. break;
  304. case GX_RGB12:
  305. break;
  306. case GX_BGR12:
  307. break;
  308. case GX_GBRG:
  309. break;
  310. case GX_BGGR:
  311. break;
  312. case GX_RGGB:
  313. break;
  314. case GX_GRBG:
  315. break;
  316. case GX_FORMAT_FIRST:
  317. qtformat = ;
  318. break;
  319. case GX_FORMAT_LAST:
  320. qtformat = ;
  321. break;
  322. default:
  323. break;
  324. };
  325. return qtformat;
  326. } */
  327.  
  328. void Qacheck::button1_Click()
  329. {
  330. /* Using the device */
  331. try
  332. {
  333. /* Capturing images */
  334. StatusBar.showMessage("Capturing images");
  335. pr.Capture();
  336.  
  337. /* Getting the MRZ data */
  338. StatusBar.showMessage("Reading MRZ");
  339. prDoc *doc = pr.GetMrz(0, PR_LIGHT_INFRA, PR_IT_ORIGINAL);
  340.  
  341. if (!doc->IsValid())
  342. StatusBar.showMessage("No MRZ data found!");
  343. else
  344. {
  345. MainWindow win;
  346. win.setText1("");
  347. win.setText2("");
  348. win.show();
  349.  
  350. /* display the white image */
  351. prImage *img = pr.GetImage(0, PR_LIGHT_WHITE, PR_IT_ORIGINAL);
  352. fullimage = *img->GxImage();
  353.  
  354. QImage *Image = new(QImage((uchar*)fullimage.GetPixels(), fullimage.GetXSize(), fullimage.GetYSize(), fullimage.format()));
  355. // fullimage.DisplayImage(g.GetHdc(), 0, 0, fullimage.xsize(), fullimage.ysize());
  356. // pix->loadFromData(raw, len, format);
  357. // fullimage.Convert();
  358. QPainter Painter(Image);
  359. QGraphicsScene *scene = new(QGraphicsScene); -
  360. QGraphicsPixmapItem *pixi = new(QGraphicsPixmapItem);
  361. pixi = scene->addPixmap(QPixmap(Pixmap));
  362. ui->graphicsView->setScene(scene);
  363. pictureBox1.Image = Pixmap;
  364. // g.Dispose();
  365.  
  366. /* access the document variant */
  367. gxVariant *pdoc = doc->ToVariant();
  368.  
  369. /* get the row list */
  370. gxVariant rowlist;
  371. pdoc->GetChild(rowlist, GX_VARIANT_BY_ID, PRV_OCRROWLIST, 0);
  372.  
  373. /* get the global quality alert */
  374. gxVariant globalalert;
  375. rowlist.GetChild(globalalert, GX_VARIANT_BY_ID, PRV_OQCA, 0);
  376. int iglobalalert = globalalert.GetInt();
  377. if (iglobalalert != 0)
  378. win.setAppendText1("Global:" + getalertstr(iglobalalert) + "\r\n");
  379.  
  380. /* list the rows */
  381. int nrows = rowlist.GetNItems();
  382. for (int r = 0; r < nrows; r++) {
  383. // get the row
  384. gxVariant row;
  385. rowlist.GetItem(row, GX_VARIANT_BY_INDEX, 0, r);
  386. win.setAppendText2(QString::number(r) + ". row:" + getRowProperties(row) + "\r\n");
  387.  
  388. // get the row qca
  389. gxVariant vrow_qca;
  390. row.GetChild(vrow_qca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
  391. // print row qca
  392. int irow_qca = vrow_qca.GetInt();
  393.  
  394. // get the row frame
  395. gxVariant vrow_frame;
  396. row.GetChild(vrow_frame, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
  397. gxPG4 row_frame = vrow_frame.GetGxPG4();
  398.  
  399. //// draw the row frame on alert
  400. //if (irow_qca != 0)
  401. // drawframe(fullimage, bmp, row_frame, irow_qca);
  402. if (irow_qca != 0)
  403. win.setAppendText1(QString::number(r) + ". row:" + getalertstr(irow_qca));
  404. fullimage.DisplayImage()
  405. // list the characters
  406. int nchars = row.GetNItems();
  407. for (int c = 0; c < nchars; c++)
  408. {
  409. gxVariant character;
  410. row.GetItem(character, GX_VARIANT_BY_INDEX, 0, c);
  411. win.setText2("\t" + QString::number(c) + ". char:" + getCharProperties(character) + "\r\n");
  412.  
  413. // get the character qca
  414. gxVariant vchar_qca;
  415. character.GetChild(vchar_qca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
  416. int ichar_qca = vchar_qca.GetInt();
  417.  
  418. // get the character frame
  419. gxVariant vchar_frame;
  420. character.GetChild(vchar_frame, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
  421. gxPG4 char_frame = vchar_frame.GetGxPG4();
  422.  
  423. // draw the character frame on alert
  424. if (ichar_qca != 0)
  425. drawframe(fullimage, Image, char_frame, ichar_qca);
  426.  
  427. if (ichar_qca != 0)
  428. win.setAppendText1("\t" + QString::number(c) + ". char:" + getalertstr(ichar_qca));
  429. }
  430.  
  431. win.setAppendText1("\r\n");
  432. }
  433. }
  434. }
  435.  
  436. catch (gxException ex)
  437. {
  438. StatusBar.showMessage(ex.GetErrorStringA().c_str());
  439. }
  440. }
Add Comment
Please, Sign In to add comment