void test_video() { VideoCapture cap(CV_CAP_ANY); ImageProcessor processor; ImageLoader loader; NeuralNetwork net; net.load(NET_FILE_NAME); //net.visualize_hidden_units(1, 50); if (!cap.isOpened()) { cout << "Failed to initialize camera\n"; return; } namedWindow("CameraCapture"); namedWindow("ProcessedCapture"); cv::Mat frame; while (true) { cap >> frame; cv::Mat processedFrame = processor.process_image(frame); if(processedFrame.rows * processedFrame.cols == INPUT_LAYER_SIZE) { mat input = loader.to_arma_mat(processedFrame); int label = net.predict(input); if(label == 0) putText(frame, "A", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8); else if(label == 1) putText(frame, "E", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8); else if(label == 2) putText(frame, "I", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8); else if(label == 3) putText(frame, "O", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8); else if(label == 4) putText(frame, "U", Point(500, 300), FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(0), 3, 8); } imshow("CameraCapture", frame); imshow("ProcessedCapture", processedFrame); int key = waitKey(5); if(key == 13) { imwrite("captura.jpg", frame); } if (key == 27) break; } destroyAllWindows(); }
int main( int argc, char** argv ) { if(argc == 3) { ImageProcessor* proc = new ImageProcessor(argv[2]); VideoCapture cap; if(!cap.open(argv[1])) { cout << ERROR_STR << "Failed to open " << argv[1] << endl; return -1; } namedWindow("Video output", 1); namedWindow("Input", 1); namedWindow("Settings", 1); createTrackbar("hi", "Settings", &hi, 255); createTrackbar("lo", "Settings", &lo, 255); //createTrackbar("min_hue", "Settings", &minhue, 180); //createTrackbar("max_hue", "Settings", &maxhue, 180); createTrackbar("sat", "Settings", &minsat, 255); createTrackbar("val", "Settings", &minval, 255); namedWindow("Found circles", 1); for(;;) { Mat curFrame; cap >> curFrame; if (curFrame.empty()) { cout << STATUS_STR << "Frame is empty" << endl; break; } else { //resize(curFrame, curFrame, Size(), 0.4, 0.4, INTER_AREA); Mat fr = proc->process_image(curFrame); imshow("Video output", fr); imshow("Input", curFrame); // cout << "hi = " << hi << " lo = " << lo << endl; if(fr.empty()) { cout << STATUS_STR << "Processed frame is empty" << endl; break; } } cvWaitKey(5); if(waitKey(30) >= 0) break; } }