int main(int argc, const char **argv) { /* * At least 1 parameter required */ if(argc < 2) { printUsageInfo(); return -1; } /* * Handle cmd arguments */ if(!handleInputParameters(argc, argv)) { printUsageInfo(); return -1; } /* * Input and output files must be defined */ if(inputFile.empty() || outputFile.empty()) { printf("Must specify both, input and output files\n"); printUsageInfo(); return -1; } /* * Input and output files must differ */ if(inputFile == outputFile) { printf("Input file must not be the same as the output file\n"); return -1; } if(fileExists(outputFile.c_str())) { std::string input; printf("************************************************************\n"); printf("File %s exists, overwrite (yes/no)\n", outputFile.c_str()); printf("************************************************************\n"); while(input != "yes" && input != "no") { std::getline(std::cin, input); if(input == "no") { printf("Run the program and change the -o option\n"); return -1; } else if(input == "yes") { printf("overwriting %s\n", outputFile.c_str()); break; } } } calib::CameraCalibContainer camContainer; std::vector<calib::LEDCalibContainer> LEDContainers; if(!readCalibData(inputFile.c_str(), camContainer, LEDContainers)) { printf("Could not read %s\n", inputFile.c_str()); return -1; } int imgW = camContainer.imgSize.width; calib::CameraCalibContainer camContainerFlip = camContainer; // copy { /****************************************************************** * Flip the camera samples ******************************************************************/ std::vector<calib::CameraCalibSample> &camSamplesFlip = camContainerFlip.getSamples(); for(int i = 0; i < (int)camSamplesFlip.size(); ++i) { std::vector<cv::Point2f> &imagePointsFlip = camSamplesFlip[i].image_points; // invert for(size_t j = 0; j < imagePointsFlip.size(); ++j) { imagePointsFlip[j].x = imgW - imagePointsFlip[j].x - 1; } for(int row = 0; row < 5; ++row) { for(int col = 0; col < 4; ++col) { int nInd1 = row * 4 + col; int nInd2 = (11 - row - 1) * 4 + col; cv::Point2f &refP1 = imagePointsFlip[nInd1]; cv::Point2f &refP2 = imagePointsFlip[nInd2]; cv::Point2f tmp = refP1; refP1 = refP2; refP2 = tmp; } } } } /****************************************************************** * Flip the LED samples ******************************************************************/ // copy std::vector<calib::LEDCalibContainer> LEDContainersFlip = LEDContainers; for(size_t cContainer = 0; cContainer < LEDContainersFlip.size(); ++cContainer) { std::vector<calib::LEDCalibSample> &LEDSamplesFlip = LEDContainersFlip[cContainer].getSamples(); for(int cSample = 0; cSample < (int)LEDSamplesFlip.size(); ++cSample) { calib::LEDCalibSample &curSample = LEDSamplesFlip[cSample]; std::vector<cv::Point2f> &imagePointsFlip = curSample.image_points; cv::Point2d &glintFlip = curSample.glint; glintFlip.x = imgW - glintFlip.x - 1; // invert for(size_t j = 0; j < imagePointsFlip.size(); ++j) { imagePointsFlip[j].x = imgW - imagePointsFlip[j].x - 1; } } } // enumerate the image points enumerateLEDImagePoints(LEDContainersFlip); { /****************************************************************** * Calibrate the camera with the fipped samples ******************************************************************/ printf("Calibrating the camera with flipped samples..."); fflush(stdout); calib::CameraCalibrator::calibrateCamera(camContainerFlip); printf("ok\n"); } { printf("Calibrating the LEDs with flipped samples...\n"); Camera camFlip; camFlip.setIntrinsicMatrix(camContainerFlip.intr); camFlip.setDistortion(camContainerFlip.dist); int nFlipLEDs = LEDContainersFlip.size(); for(int i = 0; i < nFlipLEDs; ++i) { calib::calibrateLED(LEDContainersFlip[i], camFlip); } } printf("******************************************************************\n"); printf("Original, not flipped\n"); printCameraData(camContainer); printLEDData(LEDContainers); printf("******************************************************************\n"); printf("New, flipped\n"); printCameraData(camContainerFlip); printLEDData(LEDContainersFlip); CalibDataWriter writer; if(!writer.create(outputFile.c_str())) { printf("Could not create %s\n", outputFile.c_str()); return -1; } if(!writer.writeCameraData(camContainerFlip)) { printf("Could not write the camera data into the xml file\n"); return -1; } if(!writer.writeLEDData(LEDContainersFlip)) { printf("Could not write the LED data into the xml file\n"); return -1; } printf("XML file %s written\n", outputFile.c_str()); return 0; }
int main(const int argc, const char **args) { if(argc < 2) { printUsageInfo(); return -1; } if(!handleInputParameters(argc, args)) { printUsageInfo(); return -1; } if(bPrintHelp) { printUsageInfo(); return 0; } if(inputFolder.empty()) { printf("-i <input_folder> Must be defined\n"); printUsageInfo(); return -1; } if(!resStreamer.init(inputFolder)) { return -1; } cv::VideoWriter videoWriterEye; cv::VideoWriter videoWriterScene; int fps = resStreamer.getFps(); if(!outputFolder.empty()) { // int ex = resStreamer.getFourCC(); int ex = CV_FOURCC('P','I','M','1'); cv::Size imgDim = resStreamer.getDim(); videoWriterEye.open(outputFolder + "camera1.mjpg" , ex, fps, imgDim, true); if(!videoWriterEye.isOpened()) { return false; } videoWriterScene.open(outputFolder + "camera2.mjpg" , ex, fps, imgDim, true); if(!videoWriterScene.isOpened()) { return false; } bBurnVideos = true; } else { bShowFrames = true; } /********************************************************************** * Initialize the main window *********************************************************************/ const std::string strWinEye("Eye window"); const std::string strWinScene("Scene window"); if(bShowFrames) { cv::namedWindow(strWinEye, CV_WINDOW_AUTOSIZE); cv::namedWindow(strWinScene, CV_WINDOW_AUTOSIZE); } // displayed image cv::Mat imgEye, imgScene; struct timeval t1; gettimeofday(&t1, NULL); /********************************************************************** * Main loop *********************************************************************/ while(b_running) { ResultData data; if(!b_paused) { int ret = resStreamer.get(imgEye, imgScene, data); switch(ret) { case ResultStreamer::STREAM_FINISHED: { printf("stream ended\n"); return 0; } case ResultStreamer::STREAM_ERROR: { printf("Stream error\n"); return -1; } default: break; } } if(bFlipY) { cv::flip(imgEye, imgEye, 1); } // analyse and draw the results // TODO: add the scene image draw(imgEye, imgScene, data); if(bShowFrames) { // get the key state int periodMs = 1000.0 / (double)fps; struct timeval t2; gettimeofday(&t2, NULL); long dSec = t2.tv_sec - t1.tv_sec; long dUsec = t2.tv_usec - t1.tv_usec; int dMillis = (int)(1000.0 * dSec + dUsec / 1000.0 + 0.5); int dur = std::max(2, periodMs - dMillis); t1 = t2; int key = cv::waitKey(dur); handleKeyboard(key); // show the frames cv::imshow(strWinEye, imgEye); cv::imshow(strWinScene, imgScene); } if(bBurnVideos) { videoWriterEye << imgEye; videoWriterScene << imgScene; } } return EXIT_SUCCESS; }
void getCMD(int argc, char ** argv, QString& binary, QString& args, QString& path){ //Get the input file QString inFile; bool showDLG = false; //flag to bypass any default application setting if(argc > 1){ for(int i=1; i<argc; i++){ if(QString(argv[i]).simplified() == "-select"){ showDLG = true; }else{ inFile = argv[i]; break; } } }else{ printUsageInfo(); } //Make sure that it is a valid file/URL bool isFile=false; bool isUrl=false; if(QFile::exists(inFile)){ isFile=true; } else if(QUrl(inFile).isValid()){ isUrl=true; } if( !isFile && !isUrl ){ qDebug() << "Error: Invalid file or URL"; return;} //Determing the type of file (extension) QString extension; if(isFile){ QFileInfo info(inFile); extension=info.completeSuffix(); if(info.isDir()){ extension="directory"; } else if(info.isExecutable() && extension!="desktop"){ extension="binary"; } }else if(isUrl){ extension = inFile.section(":",0,0); } //if not an application - find the right application to open the file QString cmd; bool useInputFile = false; if(extension=="desktop" && !showDLG){ bool ok = false; XDGDesktop DF = LXDG::loadDesktopFile(inFile, ok); if(!ok){ qDebug() << "[ERROR] Input *.desktop file could not be read:" << inFile; exit(1); } switch(DF.type){ case XDGDesktop::APP: if(!DF.exec.isEmpty()){ cmd = LXDG::getDesktopExec(DF); if(!DF.path.isEmpty()){ path = DF.path; } }else{ qDebug() << "[ERROR] Input *.desktop application file is missing the Exec line:" << inFile; exit(1); } break; case XDGDesktop::LINK: if(!DF.url.isEmpty()){ //This is a URL - so adjust the input variables appropriately inFile = DF.url; cmd.clear(); extension = inFile.section(":",0,0); }else{ qDebug() << "[ERROR] Input *.desktop link file is missing the URL line:" << inFile; exit(1); } break; case XDGDesktop::DIR: if(!DF.path.isEmpty()){ //This is a directory link - adjust inputs inFile = DF.path; cmd.clear(); extension = "directorypath"; }else{ qDebug() << "[ERROR] Input *.desktop directory file is missing the Path line:" << inFile; exit(1); } break; default: qDebug() << "[ERROR] Unknown *.desktop file type:" << inFile; exit(1); } } if(cmd.isEmpty()){ if(extension=="binary"){ cmd = inFile; } else{ //Find out the proper application to use this file/directory useInputFile=true; cmd = cmdFromUser(argc, argv, inFile, extension, path, showDLG); } } //qDebug() << "Found Command:" << cmd << "Extension:" << extension; //Clean up the command appropriately for output if(cmd.contains("%")){cmd = cmd.remove("%U").remove("%u").remove("%F").remove("%f").simplified(); } binary = cmd; if(useInputFile){ args = inFile; } }
void getCMD(int argc, char ** argv, QString& binary, QString& args, QString& path, bool& watch){ //Get the input file //Make sure to load the proper system encoding first LUtils::LoadTranslation(0,""); //bypass application modification QString inFile, ActionID; bool showDLG = false; //flag to bypass any default application setting if(argc > 1){ for(int i=1; i<argc; i++){ if(QString(argv[i]).simplified() == "-select"){ showDLG = true; }else if(QString(argv[i]).simplified() == "-volumeup"){ int vol = LOS::audioVolume()+5; //increase 5% if(vol>100){ vol=100; } LOS::setAudioVolume(vol); showOSD(argc,argv, QString(QObject::tr("Audio Volume %1%")).arg(QString::number(vol)) ); return; }else if(QString(argv[i]).simplified() == "-volumedown"){ int vol = LOS::audioVolume()-5; //decrease 5% if(vol<0){ vol=0; } LOS::setAudioVolume(vol); showOSD(argc,argv, QString(QObject::tr("Audio Volume %1%")).arg(QString::number(vol)) ); return; }else if(QString(argv[i]).simplified() == "-brightnessup"){ int bright = LOS::ScreenBrightness(); if(bright > 0){ //brightness control available bright = bright+5; //increase 5% if(bright>100){ bright = 100; } LOS::setScreenBrightness(bright); showOSD(argc,argv, QString(QObject::tr("Screen Brightness %1%")).arg(QString::number(bright)) ); } return; }else if(QString(argv[i]).simplified() == "-brightnessdown"){ int bright = LOS::ScreenBrightness(); if(bright > 0){ //brightness control available bright = bright-5; //decrease 5% if(bright<0){ bright = 0; } LOS::setScreenBrightness(bright); showOSD(argc,argv, QString(QObject::tr("Screen Brightness %1%")).arg(QString::number(bright)) ); } return; }else if( (QString(argv[i]).simplified() =="-action") && (argc>(i+1)) ){ ActionID = QString(argv[i+1]); i++; //skip the next input }else{ inFile = QString::fromLocal8Bit(argv[i]); break; } } }else{ printUsageInfo(); } //Make sure that it is a valid file/URL bool isFile=false; bool isUrl=false; if(QFile::exists(inFile)){ isFile=true; } else if(QFile::exists(QDir::currentPath()+"/"+inFile)){isFile=true; inFile = QDir::currentPath()+"/"+inFile;} //account for relative paths else if(QUrl(inFile).isValid() && !inFile.startsWith("/") ){ isUrl=true; } if( !isFile && !isUrl ){ ShowErrorDialog( argc, argv, QString(QObject::tr("Invalid file or URL: %1")).arg(inFile) ); } //Determing the type of file (extension) QString extension; //qDebug() << "File Type:" << isFile << isUrl; if(isFile){ QFileInfo info(inFile); extension=info.suffix(); //qDebug() << " - Extension:" << extension; if(info.isDir()){ extension="directory"; } else if(info.isExecutable() && extension.isEmpty()){ extension="binary"; } else if(extension!="desktop"){ extension="mimetype"; } //flag to check for mimetype default based on file } else if(isUrl && inFile.startsWith("mailto:")){ extension = "email"; } else if(isUrl){ extension = "webbrowser"; } //qDebug() << "Input:" << inFile << isFile << isUrl << extension; //if not an application - find the right application to open the file QString cmd; bool useInputFile = false; if(extension=="desktop" && !showDLG){ bool ok = false; XDGDesktop DF = LXDG::loadDesktopFile(inFile, ok); if(!ok){ ShowErrorDialog( argc, argv, QString(QObject::tr("File could not be opened: %1")).arg(inFile) ); } switch(DF.type){ case XDGDesktop::APP: if(!DF.exec.isEmpty()){ cmd = LXDG::getDesktopExec(DF,ActionID); if(!DF.path.isEmpty()){ path = DF.path; } watch = DF.startupNotify; }else{ ShowErrorDialog( argc, argv, QString(QObject::tr("Application shortcut is missing the launching information (malformed shortcut): %1")).arg(inFile) ); } break; case XDGDesktop::LINK: if(!DF.url.isEmpty()){ //This is a URL - so adjust the input variables appropriately inFile = DF.url; cmd.clear(); extension = inFile.section(":",0,0); watch = DF.startupNotify; }else{ ShowErrorDialog( argc, argv, QString(QObject::tr("URL shortcut is missing the URL: %1")).arg(inFile) ); } break; case XDGDesktop::DIR: if(!DF.path.isEmpty()){ //This is a directory link - adjust inputs inFile = DF.path; cmd.clear(); extension = "directory"; watch = DF.startupNotify; }else{ ShowErrorDialog( argc, argv, QString(QObject::tr("Directory shortcut is missing the path to the directory: %1")).arg(inFile) ); } break; default: qDebug() << DF.type << DF.name << DF.icon << DF.exec; ShowErrorDialog( argc, argv, QString(QObject::tr("Unknown type of shortcut : %1")).arg(inFile) ); } } if(cmd.isEmpty()){ if(extension=="binary" && !showDLG){ cmd = inFile; } else{ //Find out the proper application to use this file/directory useInputFile=true; cmd = cmdFromUser(argc, argv, inFile, extension, path, showDLG); if(cmd.isEmpty()){ return; } } } //Now assemble the exec string (replace file/url field codes as necessary) if(useInputFile){ args = inFile; //just to keep them distinct internally // NOTE: lumina-open is only designed for a single input file, // so no need to distinguish between the list codes (uppercase) // and the single-file codes (lowercase) //Special "inFile" format replacements for input codes if( (cmd.contains("%f") || cmd.contains("%F") ) ){ //Apply any special field replacements for the desired format inFile.replace("%20"," "); //Now replace the field codes cmd.replace("%f","\""+inFile+"\""); cmd.replace("%F","\""+inFile+"\""); }else if( (cmd.contains("%U") || cmd.contains("%u")) ){ //Apply any special field replacements for the desired format if(!inFile.contains("://")){ inFile.prepend("file:"); } //local file - add the extra flag inFile.replace(" ", "%20"); //Now replace the field codes cmd.replace("%u","\""+inFile+"\""); cmd.replace("%U","\""+inFile+"\""); }else{ //No field codes (or improper field codes given in the file - which is quite common) // - Just tack the input file on the end and let the app handle it as necessary cmd.append(" \""+inFile+"\""); } } //qDebug() << "Found Command:" << cmd << "Extension:" << extension; //Clean up any leftover "Exec" field codes (should have already been replaced earlier) if(cmd.contains("%")){cmd = cmd.remove("%U").remove("%u").remove("%F").remove("%f").remove("%i").remove("%c").remove("%k").simplified(); } binary = cmd; //pass this string to the calling function }
int main(int argc, const char **args) { if(argc < 2) { printUsageInfo(); return EXIT_FAILURE; } if(!handleInputParameters(argc, args)) { printUsageInfo(); return EXIT_FAILURE; } if(bPrintHelp) { printUsageInfo(); return EXIT_SUCCESS; } if(inputFile.empty()) { printf("-i <input_file> must be defined\n"); printUsageInfo(); return EXIT_FAILURE; } /* * Read the contents of the XML file */ calib::CameraCalibContainer camContainer; if(!readCalibData(inputFile.c_str(), camContainer, LEDContainers)) { return EXIT_FAILURE; } /* * Not interested in empty containers. */ if(LEDContainers.size() == 0) { printf("No LED containers\n"); return EXIT_FAILURE; } if(LEDContainers[0].getSamples().size() == 0) { printf("Empty LED container\n"); return EXIT_FAILURE; } if(camContainer.getSamples().size() == 0) { printf("Empty Cam container\n"); return EXIT_FAILURE; } /********************************************************************** * Initialize the main window *********************************************************************/ const std::string strWinSample("Sample window"); cv::namedWindow(strWinSample, CV_WINDOW_AUTOSIZE); cvSetMouseCallback(strWinSample.c_str(), onMouse, 0); animator.setText("Start"); /********************************************************************** * Main loop *********************************************************************/ cv::Mat img; while(b_running) { // analyse and draw the results if(bUpdateGraphics) { const calib::LEDCalibSample &sample = LEDContainers[indContainer].getSamples()[indSample]; draw(img, sample); bUpdateGraphics = false; } cv::Mat imgRender; img.copyTo(imgRender); animator.update(imgRender); int key = cv::waitKey(3); handleKeyboard(key); // show the frames cv::imshow(strWinSample, imgRender); } if(!outputFile.empty()) { if(!writeCalibData(camContainer, LEDContainers)) { return EXIT_FAILURE; } } return EXIT_SUCCESS; }