Ejemplo n.º 1
0
int processImagePair() {

    namedWindow("Main", CV_WINDOW_KEEPRATIO); //resizable window;

    Mat sceneRgbImage, sceneGrayImage;

    sceneRgbImage = cv::imread(path + "/images/card_frame.jpg");
    if (sceneRgbImage.empty()) {
        std::cout << "Scene image cannot be read" << std::endl;
        return 1;
    }

    cvtColor(sceneRgbImage, sceneGrayImage, CV_RGB2GRAY);

    Controller *controller = Controller::getInstance();

    if (!controller->isInitialized) {
        controller->initialize(sceneRgbImage, path);
    }

    controller->isModeObjectDetection(true);

    // call display function with frame data
    bool shouldQuit = false;
    do {

        // display single window with one analyzer configuration
        controller->displayFunction(sceneRgbImage, sceneGrayImage);

        // Read the keyboard input:
        int keyCode = cv::waitKey(5);
        if (keyCode == 27 || keyCode == 'q') {
            shouldQuit = true;
        }
    } while (!shouldQuit);

    return 0;
}
Ejemplo n.º 2
0
int processVideo() {

    VideoCapture capture(1);

    if (!capture.isOpened()) {
        cerr << "Failed to open video stream\n" << endl;
        return 1;
    }

    namedWindow("Main", CV_WINDOW_KEEPRATIO); //resizable window;

    Mat rgbFrame, grayFrame;
    capture.read(rgbFrame);

    // Try to read the pattern:
    cv::Mat patternImage, patternImageGray;
    patternImage = cv::imread(path + "/images/card.jpg");
    if (patternImage.empty()) {
        std::cout << "Input image cannot be read" << std::endl;
        return 2;
    }
    cvtColor(patternImage, patternImageGray, CV_RGB2GRAY);

    Controller *controller = Controller::getInstance();

    for (; ;) {
        capture.read(rgbFrame);
        if (rgbFrame.empty()) break;

        if (!controller->isInitialized) {
            controller->initialize(rgbFrame, path);
        }

        cvtColor(rgbFrame, grayFrame, CV_RGB2GRAY);
        if (grayFrame.empty()) {
            std::cout << "Cannot open video capture device" << std::endl;
        }

        // call display function with frame data
        controller->displayFunction(rgbFrame, grayFrame);

        imshow("Main", rgbFrame);

        char key = (char) waitKey(5); //delay N millis, usually long enough to display and capture input
        switch (key) {
            case 'q':
                controller->isModeObjectDetection(true);
                cout << "Recognition started.." << endl;
                break;
            case 'w':
                controller->isModeObjectDetection(false);
                cout << "Recognition stopped!" << endl;
                break;
            case 'e':
                controller->isModeTracking(true);
                cout << "Tracking started.." << endl;
                break;
            case 'r':
                controller->isModeTracking(false);
                cout << "Tracking stopped!" << endl;
                break;
            case 's':
                controller->createObjectPattern(patternImage, patternImageGray);
                cout << "Image registered" << endl;
                break;
            case 'd':
                controller->createObjectPattern(rgbFrame, grayFrame);
                cout << "Frame registered" << endl;
                break;
            case 't':
                cout << "Configure SURF as detector" << endl;
                cout << "RESULT=" << controller->setDetector("SURF");
                break;
            case 'z':
                cout << "Configure SURF as extractor" << endl;
                cout << "RESULT=" << controller->setExtractor("SURF");
                break;
            case 'u':
                cout << "Configure BF as matcher" << endl;
                cout << "RESULT=" << controller->setMatcher("BF");
                break;
            case 27: //escape key
                return 0;
            default:
                break;
        }
    }
}