// TODO implement these cv::Mat eyeCornerMap(const cv::Mat ®ion, bool left, bool left2) { cv::Mat cornerMap; cv::Size sizeRegion = region.size(); cv::Range colRange(sizeRegion.width / 4, sizeRegion.width * 3 / 4); cv::Range rowRange(sizeRegion.height / 4, sizeRegion.height * 3 / 4); cv::Mat miRegion(region, rowRange, colRange); cv::filter2D(miRegion, cornerMap, CV_32F, (left && !left2) || (!left && !left2) ? leftCornerKernel : rightCornerKernel); return cornerMap; }
//Preview selected file void QxMainWindow::preview() { QListWidgetItem *pCurrentItem = m_pFileListWidget->currentItem(); if (!pCurrentItem) { return; } QString strFileName = pCurrentItem->text(); QFile file(strFileName); if (!file.open(QIODevice::ReadOnly)) { return; } QByteArray rawData = file.readAll(); file.close(); cv::Size imageSize(640,448); //the image used to preview some of the characters const unsigned uCharacterWidth = 64; //the width of each character in the preview image const unsigned uCharacterHeight = 64; //the height of each character in the preview image cv::Size smallerSize(54, 54);; //to guarantee a certain distance among characters, characters are presented in smaller size than they are. const quint32 uInterval = 5; //this should be calculated by (characterSize.width-smallerSize.width)/2; quint32 uCharacterPerRow = imageSize.width / uCharacterWidth; quint32 uCharacterPerCol = imageSize.height / uCharacterHeight; cv::Mat img = 255 * cv::Mat::ones(imageSize, CV_8UC1); quint32 uDecodedByteNum = 0; //As the data is read as a stream, this variable tells how many bytes are processed already for (quint32 i = 0; i != uCharacterPerRow; ++i) { for (quint32 j = 0; j != uCharacterPerCol; ++j) { quint32 uWidth = uchar(rawData.at(6 + uDecodedByteNum)) + quint32(uchar(rawData.at(7 + uDecodedByteNum))) * (1 << 8); quint32 uHeight = uchar(rawData.at(8 + uDecodedByteNum)) + quint32(uchar(rawData.at(9 + uDecodedByteNum))) * (1 << 8); quint32 uArcLen = uWidth > uHeight ? uWidth : uHeight; uDecodedByteNum += 10; // save data to a pre-defined white image(all pixel values are pre-defined to be 255) cv::Mat characterImage = 255 * cv::Mat::ones(uArcLen, uArcLen, CV_8UC1); quint32 uHalfPadRowNum = (uArcLen - uHeight) / 2; quint32 uHalfPadColNum = (uArcLen - uWidth) / 2; for (quint32 row = uHalfPadRowNum; row != uHeight + uHalfPadRowNum; ++row) { uchar *pRow = characterImage.ptr<uchar>(row); for (quint32 col = uHalfPadColNum; col != uWidth + uHalfPadColNum; ++col) { pRow[col] = uchar(rawData.at(uDecodedByteNum++)); } } // image normalization and filling cv::resize(characterImage, characterImage, smallerSize); cv::Range rowRange(j*uCharacterWidth, (j + 1)*uCharacterWidth); cv::Range colRange(i*uCharacterHeight, (i + 1)*uCharacterHeight); cv::Mat roi = img(rowRange, colRange); //cv::Mat::copyTo() calls cv::Mat::create(), which breaks the original image. //Also, cv::Mat::clone() fails to copy the values properly somehow, thus a pixelwise copy is implemented here. for (int row = 0; row != smallerSize.height; ++row) { uchar *pDst = roi.ptr<uchar>(row + uInterval); uchar *pSrc = characterImage.ptr<uchar>(row); for (int col = 0; col != smallerSize.width; ++col) { pDst[col + uInterval] = pSrc[col]; } } } } QImage previewImage(img.data, img.cols, img.rows, img.step, QImage::Format_Grayscale8); QPixmap pixmap = QPixmap::fromImage(previewImage); m_pPreviewLabel->setPixmap(pixmap); m_pPreviewLabel->show(); }