Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "qacheck.h"
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "prapi.h"
- #include <QObject>
- #include <QMessageBox>
- #include <QString>
- #include <QBitmap>
- #include <QPen>
- #include <QColor>
- #include <QPixmap>
- #include <QImage>
- #include <QPainter>
- #include <QGraphicsScene>
- #include <QGraphicsPixmapItem>
- #include <QStatusBar>
- Qacheck::Qacheck()
- {
- // InitializeComponent();
- QMessageBox msgBox;
- try
- {
- /* Opening the PR system */
- StatusBar.showMessage("Opening system files");
- /* Validity check */
- if (!pr.IsValid())
- {
- msgBox.setText("Failed to initialize!");
- msgBox.exec();
- // this.Close();
- return;
- }
- /* Turn on quality check */
- pr.SetProperty("document/mrz_quality_check", 1);
- /* Set the the range of PR_OQA_CHARDISTANCE */
- pr.SetProperty("document/mqc/chardistancemin", 2000); // 2000 micron or 2 mm
- pr.SetProperty("document/mqc/chardistancemax", 3000); // 3000 micron or 3 mm
- /* Connecting to the first device */
- StatusBar.showMessage("Connecting to the first device");
- pr.UseDevice(0, PR_UMODE_FULL_CONTROL);
- }
- catch (gxException ex)
- {
- msgBox.setText(ex.GetErrorStringA().c_str());
- msgBox.exec();
- // this.Close();
- }
- }
- Qacheck::~Qacheck()
- {
- // delete ui;
- }
- QString Qacheck::getRowProperties(gxVariant vrow)
- {
- QString s = "";
- // PRV_OQCA
- gxVariant voqca;
- vrow.GetChild(voqca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
- s += QString(" OQCA = ") + voqca.GetASCII(voqca.GetSize()).c_str() + ";";
- // PRV_WINDOWFRAME
- gxVariant vframe;
- vrow.GetChild(vframe, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
- gxPG4 frame = vframe.GetGxPG4();
- s += QString(" X1 = ") + frame.x1 + ";";
- s += QString(" Y1 = ") + frame.y1 + ";";
- s += QString(" X2 = ") + frame.x2 + ";";
- s += QString(" Y2 = ") + frame.y2 + ";";
- s += QString(" X3 = ") + frame.x3 + ";";
- s += QString(" Y3 = ") + frame.y3 + ";";
- s += QString(" X4 = ") + frame.x4 + ";";
- s += QString(" Y4 = ") + frame.y4 + ";";
- // PRV_OQC_ROTATION
- gxVariant voqc_rotation;
- vrow.GetChild(voqc_rotation, GX_VARIANT_BY_ID, PRV_OQC_ROTATION, 0);
- s += QString(" ROTATION = ") + voqc_rotation.GetASCII(voqc_rotation.GetSize()).c_str() + ";";
- // PRV_OQC_WIDTH
- gxVariant voqc_width;
- vrow.GetChild(voqc_width, GX_VARIANT_BY_ID, PRV_OQC_WIDTH, 0);
- s += QString(" WIDTH = ") + voqc_width.GetASCII(voqc_width.GetSize()).c_str() + ";";
- // PRV_OQC_HANGOUT
- gxVariant voqc_hangout;
- vrow.GetChild(voqc_hangout, GX_VARIANT_BY_ID, PRV_OQC_HANGOUT, 0);
- s += QString(" HANGOUT = ") + voqc_hangout.GetASCII(voqc_hangout.GetSize()).c_str() + ";";
- // PRV_OQC_DISTANCE
- gxVariant voqc_distance;
- vrow.GetChild(voqc_distance, GX_VARIANT_BY_ID, PRV_OQC_DISTANCE, 0);
- s += QString(" DISTANCE = ") + voqc_distance.GetASCII(voqc_distance.GetSize()).c_str() + ";";
- return s;
- }
- QString Qacheck::getCharProperties(gxVariant vchar)
- {
- QString s = "";
- // PRV_OQCA
- gxVariant voqca;
- vchar.GetChild(voqca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
- s += QString(" OQCA = ") + voqca.GetASCII(voqca.GetSize()).c_str() + ";";
- // PRV_WINDOWFRAME
- gxVariant vframe;
- vchar.GetChild(vframe, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
- gxPG4 frame = vframe.GetGxPG4();
- s += QString(" X1 = ") + frame.x1 + ";";
- s += QString(" Y1 = ") + frame.y1 + ";";
- s += QString(" X2 = ") + frame.x2 + ";";
- s += QString(" Y2 = ") + frame.y2 + ";";
- s += QString(" X3 = ") + frame.x3 + ";";
- s += QString(" Y3 = ") + frame.y3 + ";";
- s += QString(" X4 = ") + frame.x4 + ";";
- s += QString(" Y4 = ") + frame.y4 + ";";
- // PRV_OQC_ROTATION
- gxVariant voqc_rotation;
- vchar.GetChild(voqc_rotation, GX_VARIANT_BY_ID, PRV_OQC_ROTATION, 0);
- s += QString(" ROTATION = ") + voqc_rotation.GetASCII(voqc_rotation.GetSize()).c_str() + ";";
- // PRV_OQC_HEIGHT
- gxVariant voqc_height;
- vchar.GetChild(voqc_height, GX_VARIANT_BY_ID, PRV_OQC_HEIGHT, 0);
- s += QString(" HEIGHT = ") + voqc_height.GetASCII(voqc_height.GetSize()).c_str() + ";";
- // PRV_OQC_WIDTH
- gxVariant voqc_width;
- vchar.GetChild(voqc_width, GX_VARIANT_BY_ID, PRV_OQC_WIDTH, 0);
- s += QString(" WIDTH = ") + voqc_width.GetASCII(voqc_width.GetSize()).c_str() + ";";
- // PRV_OQC_HANGOUT
- gxVariant voqc_hangout;
- vchar.GetChild(voqc_hangout, GX_VARIANT_BY_ID, PRV_OQC_HANGOUT, 0);
- s += QString(" HANGOUT = ") + voqc_hangout.GetASCII(voqc_hangout.GetSize()).c_str() + ";";
- // PRV_OQC_DISTANCE
- gxVariant voqc_distance;
- vchar.GetChild(voqc_distance, GX_VARIANT_BY_ID, PRV_OQC_DISTANCE, 0);
- s += QString(" DISTANCE = ") + voqc_distance.GetASCII(voqc_distance.GetSize()).c_str() + ";";
- // PRV_OQC_CONTRAST
- gxVariant voqc_contrast;
- vchar.GetChild(voqc_contrast, GX_VARIANT_BY_ID, PRV_OQC_CONTRAST, 0);
- s += QString(" CONTRAST = ") + voqc_contrast.GetASCII(voqc_contrast.GetSize()).c_str() + ";";
- return s;
- }
- QString Qacheck::getalertstr(int alert)
- {
- QString s = "";
- if ((alert & PR_OQA_CHARPOSITION) != 0)
- s += " char position;";
- if ((alert & PR_OQA_CHARDISTANCE) != 0)
- s += " char distance;";
- if ((alert & PR_OQA_CHARROTATION) != 0)
- s += " char rotation;";
- if ((alert & PR_OQA_CHARSIZE) != 0)
- s += " char size;";
- if ((alert & PR_OQA_CONTRAST) != 0)
- s += " contrast;";
- if ((alert & PR_OQA_ERZ) != 0)
- s += " erz;";
- if ((alert & PR_OQA_ROWDISTANCE) != 0)
- s += " row distance;";
- if ((alert & PR_OQA_ROWPOSITION) != 0)
- s += " row position;";
- if ((alert & PR_OQA_ROWSIZE) != 0)
- s += " row size;";
- if ((alert & PR_OQA_SPARE) != 0)
- s += " spare;";
- return s;
- }
- void Qacheck::drawframe(gxImage fullimage, QImage *Image, gxPG4 frame, int alert)
- {
- QPainter Painter(Image);
- QPen pen;
- const int PADDING = 3;
- const int PENWIDTH = 2;
- pen.setWidth(PENWIDTH);
- switch (alert)
- {
- case PR_OQA_CHARPOSITION:
- pen.setColor(QColor("Beige"));
- break;
- case PR_OQA_CHARDISTANCE:
- pen.setColor(QColor("Brown"));
- break;
- case PR_OQA_CHARROTATION:
- pen.setColor(QColor("BurlyWood"));
- break;
- case PR_OQA_CHARSIZE:
- pen.setColor(QColor("Crimson"));
- break;
- case PR_OQA_CONTRAST:
- pen.setColor(QColor("DarkGoldenrod"));
- break;
- case PR_OQA_ERZ:
- pen.setColor(QColor("DarkCyan"));
- break;
- case PR_OQA_ROWDISTANCE:
- pen.setColor(QColor("DarkViolet"));
- break;
- case PR_OQA_ROWPOSITION:
- pen.setColor(QColor("DeepPink"));
- break;
- case PR_OQA_ROWROTATION:
- pen.setColor(QColor("Firebrick"));
- break;
- case PR_OQA_ROWSIZE:
- pen.setColor(QColor("Gold"));
- break;
- case PR_OQA_SPARE:
- pen.setColor(QColor("Honeydew"));
- break;
- default: // alert combination
- pen.setColor(QColor("Red"));
- break;
- }
- int sw = fullimage.xsize();
- int sh = fullimage.ysize(); // the source dimension
- int dw = Image->size().width();
- int dh = Image->size().height(); // the display dimension
- // calculate the resolution conversion from micron to pixel
- double zx = (double)fullimage.xres() / 1000000;
- double zy = (double)fullimage.yres() / 1000000;
- // map the frame to the display coordinate
- frame.x1 = (int)(zx * frame.x1 * dw / sw) - PADDING;
- frame.x2 = (int)(zx * frame.x2 * dw / sw) + PADDING;
- frame.x3 = (int)(zx * frame.x3 * dw / sw) + PADDING;
- frame.x4 = (int)(zx * frame.x4 * dw / sw) - PADDING;
- frame.y1 = (int)(zy * frame.y1 * dh / sh) - PADDING;
- frame.y2 = (int)(zy * frame.y2 * dh / sh) - PADDING;
- frame.y3 = (int)(zy * frame.y3 * dh / sh) + PADDING;
- frame.y4 = (int)(zy * frame.y4 * dh / sh) + PADDING;
- // draw the frame
- Painter.setPen(pen);
- Painter.drawLine(frame.x1, frame.y1, frame.x2, frame.y2);
- Painter.drawLine(frame.x2, frame.y2, frame.x3, frame.y3);
- Painter.drawLine(frame.x3, frame.y3, frame.x4, frame.y4);
- Painter.drawLine(frame.x4, frame.y4, frame.x1, frame.y1);
- // g.Dispose();
- }
- /* QImage::Format Qacheck::gx2qtformat(gxi32 gxformat)
- {
- Qimage::Format qtformat;
- switch(gxformat) {
- case GX_UNDEF:
- break;
- case GX_GRAY:
- break;
- case RGB555:
- qtformat = QImage::Format_RGB555;
- break;
- case BGR555:
- break;
- case RGB565:
- qtformat = QImage::Format_RGB16;
- break;
- case BGR565:
- break;
- case GX_RGB:
- qtformat = QImage::Format_RGB888;
- break;
- case GX_BGR:
- break:
- case GX_RGBA:
- break
- case GX_BGRA:
- break;
- case GX_YUV422:
- break;
- case GX_GRAY12:
- qtformat = QImage::Format_RGB444;
- break;
- case GX_RGB12:
- break;
- case GX_BGR12:
- break;
- case GX_GBRG:
- break;
- case GX_BGGR:
- break;
- case GX_RGGB:
- break;
- case GX_GRBG:
- break;
- case GX_FORMAT_FIRST:
- qtformat = ;
- break;
- case GX_FORMAT_LAST:
- qtformat = ;
- break;
- default:
- break;
- };
- return qtformat;
- } */
- void Qacheck::button1_Click()
- {
- /* Using the device */
- try
- {
- /* Capturing images */
- StatusBar.showMessage("Capturing images");
- pr.Capture();
- /* Getting the MRZ data */
- StatusBar.showMessage("Reading MRZ");
- prDoc *doc = pr.GetMrz(0, PR_LIGHT_INFRA, PR_IT_ORIGINAL);
- if (!doc->IsValid())
- StatusBar.showMessage("No MRZ data found!");
- else
- {
- MainWindow win;
- win.setText1("");
- win.setText2("");
- win.show();
- /* display the white image */
- prImage *img = pr.GetImage(0, PR_LIGHT_WHITE, PR_IT_ORIGINAL);
- fullimage = *img->GxImage();
- QImage *Image = new(QImage((uchar*)fullimage.GetPixels(), fullimage.GetXSize(), fullimage.GetYSize(), fullimage.format()));
- // fullimage.DisplayImage(g.GetHdc(), 0, 0, fullimage.xsize(), fullimage.ysize());
- // pix->loadFromData(raw, len, format);
- // fullimage.Convert();
- QPainter Painter(Image);
- QGraphicsScene *scene = new(QGraphicsScene); -
- QGraphicsPixmapItem *pixi = new(QGraphicsPixmapItem);
- pixi = scene->addPixmap(QPixmap(Pixmap));
- ui->graphicsView->setScene(scene);
- pictureBox1.Image = Pixmap;
- // g.Dispose();
- /* access the document variant */
- gxVariant *pdoc = doc->ToVariant();
- /* get the row list */
- gxVariant rowlist;
- pdoc->GetChild(rowlist, GX_VARIANT_BY_ID, PRV_OCRROWLIST, 0);
- /* get the global quality alert */
- gxVariant globalalert;
- rowlist.GetChild(globalalert, GX_VARIANT_BY_ID, PRV_OQCA, 0);
- int iglobalalert = globalalert.GetInt();
- if (iglobalalert != 0)
- win.setAppendText1("Global:" + getalertstr(iglobalalert) + "\r\n");
- /* list the rows */
- int nrows = rowlist.GetNItems();
- for (int r = 0; r < nrows; r++) {
- // get the row
- gxVariant row;
- rowlist.GetItem(row, GX_VARIANT_BY_INDEX, 0, r);
- win.setAppendText2(QString::number(r) + ". row:" + getRowProperties(row) + "\r\n");
- // get the row qca
- gxVariant vrow_qca;
- row.GetChild(vrow_qca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
- // print row qca
- int irow_qca = vrow_qca.GetInt();
- // get the row frame
- gxVariant vrow_frame;
- row.GetChild(vrow_frame, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
- gxPG4 row_frame = vrow_frame.GetGxPG4();
- //// draw the row frame on alert
- //if (irow_qca != 0)
- // drawframe(fullimage, bmp, row_frame, irow_qca);
- if (irow_qca != 0)
- win.setAppendText1(QString::number(r) + ". row:" + getalertstr(irow_qca));
- fullimage.DisplayImage()
- // list the characters
- int nchars = row.GetNItems();
- for (int c = 0; c < nchars; c++)
- {
- gxVariant character;
- row.GetItem(character, GX_VARIANT_BY_INDEX, 0, c);
- win.setText2("\t" + QString::number(c) + ". char:" + getCharProperties(character) + "\r\n");
- // get the character qca
- gxVariant vchar_qca;
- character.GetChild(vchar_qca, GX_VARIANT_BY_ID, PRV_OQCA, 0);
- int ichar_qca = vchar_qca.GetInt();
- // get the character frame
- gxVariant vchar_frame;
- character.GetChild(vchar_frame, GX_VARIANT_BY_ID, PRV_WINDOWFRAME, 0);
- gxPG4 char_frame = vchar_frame.GetGxPG4();
- // draw the character frame on alert
- if (ichar_qca != 0)
- drawframe(fullimage, Image, char_frame, ichar_qca);
- if (ichar_qca != 0)
- win.setAppendText1("\t" + QString::number(c) + ". char:" + getalertstr(ichar_qca));
- }
- win.setAppendText1("\r\n");
- }
- }
- }
- catch (gxException ex)
- {
- StatusBar.showMessage(ex.GetErrorStringA().c_str());
- }
- }
Add Comment
Please, Sign In to add comment