void ScvRipper::frameStart(int frameNum) { char temp[20]; sprintf(temp,"img-%05d.png", frameNum); QString imgName(temp); QStandardItemModel* model = (QStandardItemModel*)ui.imagesview->model() ; if(imglist[frameNum-1] == imgName) { model->item(frameNum-1, 0)->setData(QColor("red"), Qt::ForegroundRole); ui.imagesview->setCurrentIndex(model->index(frameNum-1, 0)); } /* for ( int i = 0 ; i < model->rowCount() ; ++i ) { QString label = model->item( i, 0 )->data( Qt::DisplayRole ).toString() ; if(label == imgName) { model->item(i, 0)->setData(QColor("red"), Qt::ForegroundRole); } } */ }
void FaceFeatureRecognitionApp::TransferColorToGray(void) { std::string fileName; char filterName[] = "Land Files(*.txt)\0*.txt\0"; MagicCore::ToolKit::FileOpenDlg(fileName, filterName); std::string imgPath = fileName; std::string::size_type pos = imgPath.rfind("/"); if (pos == std::string::npos) { pos = imgPath.rfind("\\"); } imgPath.erase(pos); std::ifstream fin(fileName); int dataSize; fin >> dataSize; const int maxSize = 512; char pLine[maxSize]; fin.getline(pLine, maxSize); for (int dataId = 0; dataId < dataSize; dataId++) { fin.getline(pLine, maxSize); std::string imgName(pLine); imgName = imgPath + imgName; std::string::size_type pos = imgName.rfind("."); imgName.replace(pos, 5, ".jpg"); cv::Mat colorImg = cv::imread(imgName); cv::Mat grayImg; cv::cvtColor(colorImg, grayImg, CV_BGR2GRAY); colorImg.release(); cv::imwrite(imgName, grayImg); grayImg.release(); } fin.close(); }
string ImageHandler::removeDirName(string fullName){ string imgName(fullName.substr(fullName.rfind("/")+1)); //cout<<imgName<<endl; return imgName; }
bool combineTwoImagesTest(){ std::string imgName("/Users/herbert19lee/Downloads/lena.jpg"); cv::Mat img1 = cv::imread(imgName); cv::Mat img2 = cv::imread(imgName); cv::Mat dst; ImageUtil::combineTwoImages(dst, img1, img2); cv::namedWindow("combine"); cv::imshow("combine", dst); cv::waitKey(); return true; }
// ----------------------------------------------------- // --------------- TEST: ImageUtil Class --------------- // ----------------------------------------------------- // --------------- TEST1: ImageUtil:resize ------------- // ----------------------------------------------------- int ImageResize(){ std::string imgName("/Users/herbert19lee/Downloads/lena.jpg"); cv::Mat src, dst; src = cv::imread(imgName); cv::namedWindow("orig", CV_WINDOW_AUTOSIZE); cv::imshow("orig", src); std::string str[3]; str[0] = "r1/2"; str[1] = "r1/4"; str[2] = "r1/8"; for (int i = 1; i <= 3; i++) { cv::namedWindow(str[i-1], CV_WINDOW_AUTOSIZE); ImageUtil::resize(dst, src, 1/(cv::pow(static_cast<double>(2), static_cast<double>(i)))); cv::imshow(str[i-1], dst); } cv::waitKey(0); return 0; }
void FaceFeatureRecognitionApp::TestFaceDetectionInFile(void) { std::string fileName; char filterName[] = "Land Files(*.txt)\0*.txt\0"; MagicCore::ToolKit::FileOpenDlg(fileName, filterName); std::string imgPath = fileName; std::string::size_type pos = imgPath.rfind("/"); if (pos == std::string::npos) { pos = imgPath.rfind("\\"); } imgPath.erase(pos); imgPath += "/"; std::ifstream fin(fileName); int imgCount; fin >> imgCount; const int maxSize = 512; char pLine[maxSize]; fin.getline(pLine, maxSize); for (int imgId = 0; imgId < imgCount; imgId++) { fin.getline(pLine, maxSize); std::string imgName(pLine); imgName = imgPath + imgName; cv::Mat imgOrigin = cv::imread(imgName); if (imgOrigin.data == NULL) { continue; } cv::Mat grayImg; cv::cvtColor(imgOrigin, grayImg, CV_BGR2GRAY); std::vector<int> faces; int detectNum = mpFaceDetection->DetectFace(grayImg, faces); grayImg.release(); if (detectNum > 0) { std::vector<double> marks; for (int detectId = 0; detectId < detectNum; detectId++) { int baseId = detectId * 4; int topRow = faces.at(baseId); int downRow = topRow + faces.at(baseId + 3); int leftCol = faces.at(baseId + 1); int rightCol = leftCol + faces.at(baseId + 2); for (int colId = leftCol; colId <= rightCol; colId++) { marks.push_back(topRow); marks.push_back(colId); marks.push_back(downRow); marks.push_back(colId); } for (int rowId = topRow; rowId <= downRow; rowId++) { marks.push_back(rowId); marks.push_back(leftCol); marks.push_back(rowId); marks.push_back(rightCol); } } MarkPointsToImage(imgOrigin, &marks, 0, 255, 255, 1); } std::stringstream ss; ss << "./DetectResult/detectRes_" << imgId << ".jpg" << std::endl; std::string resName; ss >> resName; ss.clear(); cv::imwrite(resName, imgOrigin); imgOrigin.release(); } fin.close(); }