Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imho, you should not overcomplicate it, and switch to a much simpler design.

have a single while loop, a single waitKey() call, and dispatch to your tasks from there:

#include <iostream>
#include <thread>

#include "opencv2/nonfree/features2d.hpp"

#include "FeatureMatching.h"
#include "FaceDetection.h"
#include "AugmentedReality.h"

//Main function
int main()
{
    Mat colorImg;
    VideoCapture capture(0);
    while (cap.isOpened()) // (CHECK!!)
    {
        capture.read(colorImg);
        if (colorImg.empty())
              break;

        int k = waitKey(1);
        if (k == 49)
        {
            cout << "Detecting..." << endl;
            doMatch(colorImg);
        }
        else if (k == 50)
        {
            cout << "Detecting..." << endl;
            doDetect(colorImg);
        }
        else if (k == 51)
        {
            doAR(colorImg);
        }
        else if (k == 27)
        {
            cout << "Stop";
            break; //(!!)
        }
        imshow("HUD", colorImg);
    }
    return 0;
}

imho, you should not overcomplicate it, and switch to a much simpler design.

have a single while loop, a single waitKey() call, and dispatch to your tasks from there:

#include <iostream>
#include <thread>

#include "opencv2/nonfree/features2d.hpp"

#include "FeatureMatching.h"
#include "FaceDetection.h"
#include "AugmentedReality.h"

//Main function
int main()
{
    Mat colorImg;
    VideoCapture capture(0);
    while (cap.isOpened()) // (CHECK!!)
    {
        capture.read(colorImg);
        if (colorImg.empty())
             break;

        int k = waitKey(1);
        if (k == 49)
waitKey(10);
        switch (k) 
        {
            cout << "Detecting..." << endl;
            doMatch(colorImg);
        }
        else if (k == 50)
        {
            cout << "Detecting..." << endl;
            doDetect(colorImg);
        }
        else if (k == 51)
        {
            doAR(colorImg);
        }
        else if (k == 27)
        {
            cout << "Stop";
            break; //(!!)
case 27:  return 0;
            case 49:  doMatch(colorImg); break;
            case 50:  doDetect(colorImg); break;
            case 51:  doAR(colorImg); break;
        }
        imshow("HUD", colorImg);
    }
    return 0;
}

imho, you should not overcomplicate it, and switch to a much simpler design.

have a single while loop, a single waitKey() call, and dispatch to your tasks from there:

#include <iostream>

#include "opencv2/nonfree/features2d.hpp"

#include "FeatureMatching.h"
#include "FaceDetection.h"
#include "AugmentedReality.h"

//Main function
int main()
{
    Mat colorImg;
    VideoCapture capture(0);
    while (cap.isOpened()) // (CHECK!!)
    {
        Mat colorImg;
        capture.read(colorImg);
        if (colorImg.empty())
            break;

        int k = waitKey(10);
        switch (k) 
        {
            case 27:  return 0;
            case 49:  doMatch(colorImg); break;
            case 50:  doDetect(colorImg); break;
            case 51:  doAR(colorImg); break;
        }
        imshow("HUD", colorImg);
    }
    return 0;
}