How To Obtain Live Webcam Feed
Im new to CV and have been reading on the documentation and find some stuff clear and other things not, this is one thing thats not really clear and am failing to take off and understand this; I am using Qt I have openCV properly installed I have created a Qt widget application in my project.pro file i have the sources and libs for openCV my question is where do I actually put the openCV code and why isn't this working? I putting all the openCV code in my main method in my main.cpp at the moment. All I would like to do at the moment is open the webcam and get live feed from my local cam, How can I accomplish this and where do I need to put the openCV code if I'm not already putting this in the correct file, thanks in advance.
What I have tried main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <opencv2/opencv.hpp>
#include<opencv2/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <QTextStream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int argc, char *argv[]){
// disable buffer useless with GUI app
//setbuf(stdout, NULL);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
VideoCapture stream1(0); //0 is the id of video device.0 if you have only one camera.
if (!stream1.isOpened()) { //check if video device has been initialised
cout << "cannot open camera";
}
//unconditional loop
while (true) {
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0)
break;
}
return 0;
}