int main(int argc, char **argv) { if (argc != 2) { printf("usage: %s %s\n", argv[0], "filename"); return 0; } FILE *file = fopen(argv[1], "r"); if (!file) { perror("Could not open file.\n"); return 1; } int mode = 1; /* 1 = ucase; 0 = lcase */ char c; while ((c = fgetc(file)) && !feof(file)) { if (c == '\n') /* reset case pattern on newline */ mode = 1; if (mode) { if (c >= 'a' && c <= 'z') { printf("%c", c - 32); modeSwitch(&mode); } else if (c >= 'A' && c <= 'Z') { printf("%c", c); modeSwitch(&mode); } else printf("%c", c); } else { if (c >= 'A' && c <= 'Z') { printf("%c", c + 32); modeSwitch(&mode); } else if (c >= 'a' && c <= 'z') { printf("%c", c); modeSwitch(&mode); } else printf("%c", c); } } fclose(file); return 0; }
void* GlassesVideo::runThread(void*) { VideoCapture gl_capture(3); gl_capture.set(CV_CAP_PROP_FRAME_WIDTH , 640); gl_capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480); if(!gl_capture.isOpened()) { cout << "Cannot open glasses video !" << endl; } Mat gl_img, gl_img_OR; Mat curMat, preMat; //glassesOR glOR(&gl_img_OR); //glOR.stopRunning(); ObjectRecognition gl_or("g20111105_4.yml.gz"); Mat gl_img_bk; Mat glres_image; //display result image int gl_result=255; RobotSearch robotsearch; //robotsearch.create(); robotsearch.stopRunning(); //namedWindow("Glasses Video"); //moveWindow("Glasses Video", 645, 0); namedWindow("Video Live"); moveWindow("Video Live", 645, 0); namedWindow("Glasses_result",CV_WINDOW_NORMAL); moveWindow("Glasses_result",1000,600); //G_glassesMode = glassesOR; while(1) { gl_capture >> gl_img; cvtColor(gl_img,gl_img_bk,CV_RGB2GRAY); imshow("Video Live",gl_img_bk); waitKey(1); //----------------------------glasses Motion ------------------------ preMat = gl_img.clone(); //imshow("preMat", preMat); gl_capture >> curMat; //imshow ("cur", curMat); modeSwitch(preMat, curMat); //------------------------------------------------------------------- if(G_glassesMode == glassesOR) //OR MODE { //Open Glasses Objct Recognition //glOR.runAsync(); gl_result=255; gl_result = gl_or.find(gl_img_bk, 'G'); //if(gl_result !=255) //{ // gl_capture >> gl_img; // cvtColor(gl_img,gl_img_bk,CV_RGB2GRAY); // imshow("Video Live",gl_img); // waitKey(1); // gl_result=255; // gl_result = gl_or.find(gl_img_bk, 'G'); // /*if(gl_result !=255) // { // gl_capture >> gl_img; // cvtColor(gl_img,gl_img_bk,CV_RGB2GRAY); // imshow("Video Live",gl_img); // waitKey(1); // gl_result=255; // gl_result = gl_or.find(gl_img_bk, 'G'); // } // else gl_result=255;*/ //} //gl_result=4; if(gl_result !=255) { //-------------------------Display the result ------------------------ robotSpeak(gl_result, "name"); stringstream ret_src1; //result src ObjectRecognition::loadImage(ret_src1, gl_result, 'G', 1); glres_image = imread(ret_src1.str()); imshow("Glasses_result", glres_image); waitKey(1); //--------------------glasses goes to roobt search mode------------------ GlassesModeMutex.lock(); CB.clear(); G_glassesMode = robotSearch; G_Search_Step = 0; isDoneRobot = true; G_Target= gl_result/5; gl_result = 255; HelpStartTime = time(NULL); //RobotCommand(CameraMotion); //cameraMotion GlassesModeMutex.unlock(); ////-------------------------Open robot search thread ------------------------ if(!robotsearch.getRunning()) robotsearch.runAsync(); } } } //return 0; }
int main() { // Objects CameraInput *camera = new CameraInput(); Control *controller = new Control(); Process *processer = new Process(); Tracking *tracker = new Tracking(); Serial_Communication *serial = new Serial_Communication("/dev/ttyUSB0", "/dev/ttyUSB1"); // Serial_Communication *serial = new Serial_Communication("/dev/ttyUSB0");// #### For testing with only one arduino File_Handler *file_Handler = new File_Handler(); Window_Handler *window_Handler = new Window_Handler(); Menu *menu = new Menu(); // Threads QThread *t1 = new QThread; QThread *t2 = new QThread; QThread *t3 = new QThread; QThread *t4 = new QThread; QThread *t5 = new QThread; camera->moveToThread(t1); processer->moveToThread(t2); tracker->moveToThread(t3); serial->moveToThread(t3); controller->moveToThread(t4); file_Handler->moveToThread(t5); // Connect signals to slots. Whenever a signal is emitted in a function, its corresponding (connected) function will run. qRegisterMetaType<cv::Mat>("cv::Mat"); //Signals calling from: //Main thread QObject::connect(menu, SIGNAL(startRecording(bool)), controller, SLOT(startRecording(bool))); QObject::connect(menu, SIGNAL(stopRecording()), controller, SLOT(stopRecording())); QObject::connect(menu, SIGNAL(displayMenu(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat))); QObject::connect(menu, SIGNAL(requestDataFromFootController()), serial, SLOT(receiveDataFromFootControllerLoop())); QObject::connect(menu, SIGNAL(startHighRep()), controller, SLOT(startDelayMode())); QObject::connect(menu, SIGNAL(decreaseDelay()), controller, SLOT(decreaseDelay())); QObject::connect(menu, SIGNAL(increaseDelay()), controller, SLOT(increaseDelay())); QObject::connect(menu, SIGNAL(modeSwitch()), controller, SLOT(endMode())); QObject::connect(menu, SIGNAL(startPlayback()), file_Handler, SLOT(readFromFile())); QObject::connect(menu, SIGNAL(stopPlayback()), file_Handler, SLOT(stopVideo())); QObject::connect(menu, SIGNAL(toggleSlowMotion()), file_Handler, SLOT(toggleSlowMotion())); QObject::connect(menu, SIGNAL(toggleTracking()), controller, SLOT(toggleTracking())); //Thread 1 QObject::connect(t1, SIGNAL(started()), camera, SLOT(captureImage())); QObject::connect(camera, SIGNAL(capturedImage(cv::Mat)), controller, SLOT(inputImage(cv::Mat))); //Thread 2 QObject::connect(t2, SIGNAL(started()), controller, SLOT(processerReady())); QObject::connect(processer, SIGNAL(posXposY(int,int)), tracker, SLOT(position(int,int))); QObject::connect(processer, SIGNAL(readyForWork()), controller, SLOT(processerReady())); //Thread 3 QObject::connect(tracker, SIGNAL(directionAndSpeed(int,int)), serial, SLOT(sendDataToControlUnit(int,int))); QObject::connect(serial, SIGNAL(fromFootController(char)), menu, SLOT(giveInput(char))); //Thread 4 QObject::connect(t4, SIGNAL(started()), controller, SLOT(fileHandlerReadyToWrite())); QObject::connect(controller, SIGNAL(imageToProcess(cv::Mat)), processer, SLOT(processImage(cv::Mat))); QObject::connect(controller, SIGNAL(requestImage()), camera, SLOT(captureImage())); QObject::connect(controller, SIGNAL(imageToRecord(cv::Mat)), file_Handler, SLOT(writeImage(cv::Mat))); // QObject::connect(controller, SIGNAL(imageToShow(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat))); QObject::connect(processer, SIGNAL(processedImage(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat))); QObject::connect(controller, SIGNAL(stopMotor()), serial, SLOT(stopMotor())); //Thread 5 QObject::connect(file_Handler, SIGNAL(showFrame(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat))); QObject::connect(file_Handler, SIGNAL(readyToWrite()), controller, SLOT(fileHandlerReadyToWrite())); QObject::connect(file_Handler, SIGNAL(timeout()), file_Handler, SLOT(playVideo())); QObject::connect(file_Handler, SIGNAL(playbackEnded()), menu, SLOT(returnToLowRep())); // Starting Threads t1->start(); t2->start(); t3->start(); t4->start(); t5->start(); // menu->menu(); menu->inputHandler(); return 0; }