I´m using OpenCV for some face recognition stuff with a webcam. The thing is, whenever there is no camera installed, I get an exception. I handled that at the beginning with this code:
if (!realTime.isOpened())
{
cout << "No webcam installed!" << endl;
system("pause");
return 0;
}
realTime is an object of VideoCapture. So when I want to start the program with no webcam plugged in, I get a "No webcam installed" in the console.
But now I want the program to immediately stop whenever the webcam is plugged off. This seems to be really hard, cause my face recognition is in a while loop:
namedWindow("Face Detection", WINDOW_KEEPRATIO);
string trained_classifier_location = "C:/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml";
CascadeClassifier faceDetector;
faceDetector.load(trained_classifier_location);
vector<Rect> faces;
while (true)
{
realTime.read(videoStream);
faceDetector.detectMultiScale(videoStream, faces, 1.1, 4, CASCADE_SCALE_IMAGE, Size(20, 20));
for (int i = 0; i < faces.size(); i++)
{
Mat faceROI = videoStream(faces[i]);
int x = faces[i].x;
int y = faces[i].y;
int h = y + faces[i].height;
int w = x + faces[i].width;
rectangle(videoStream, Point(x, y), Point(w, h), Scalar(255, 0, 255), 2, 8, 0);
}
imshow("Face Detection", videoStream);
if (waitKey(10) == 27)
{
break;
}
}
I also tried it with a try-catch-statement, but the exception is thrown at
Check the return value of read (you should do that anyway). From the doc:
The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns empty image (with cv::Mat, test it with Mat::empty()).
So:
bool valid_frame = false;
while (true)
{
valid_frame = realTime.read(videoStream);
if(!valid_frame)
{
std::cout << "camera disconnected, or no more frames in video file";
break;
}
...
}
Related
I am trying to set ROI in real time camera and copy a picture in the ROI.
However, I tried many methods from Internet but it is still unsuccessful.
Part of my code is shown below:
while(!protonect_shutdown)
{
listener.waitForNewFrame(frames);
libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir];
//! [loop start]
cv::Mat(ir->height, ir->width, CV_32FC1, ir->data).copyTo(irmat);
Mat img = imread("button.png");
cv::Rect r(1,1,100,200);
cv::Mat dstroi = img(Rect(0,0,r.width,r.height));
irmat(r).convertTo(dstroi, dstroi.type(), 1, 0);
cv::imshow("ir", irmat / 4500.0f);
int key = cv::waitKey(1);
protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27));
listener.release(frames);
}
My real time camera can show the video normally. And no bugs in my program, but the picture cannot be shown in the ROI.
Does anyone have some ideas?
Any help is appreciate.
I hope I understood your question right and you want an output something like this:
I have created a rectangle of size 100x200 on the video feed and displaying an image in that rectangle.
Here is the code:
int main()
{
Mat frame,overlayFrame;
VideoCapture cap("video.avi");//use 0 for webcam
overlayFrame=imread("picture.jpg");
if (!cap.isOpened())
{
cout << "Could not capture video";
return -1;
}
Rect roi(1,1,100,200);//creating a rectangle of size 100x200 at point (1,1) on the videofeed
namedWindow("CameraFeed");
while ((cap.get(CV_CAP_PROP_POS_FRAMES) + 1) < cap.get(CV_CAP_PROP_FRAME_COUNT))
{
cap.read(frame);
resize(overlayFrame, overlayFrame, resize(overlayFrame, overlayFrame, Size(roi.width, roi.height));//changing the size of the image to fit in the roi
overlayFrame.copyTo(frame(roi));//copying the picture to the roi
imshow("CameraFeed", frame);
if (waitKey(27) >= 0)
break;
}
destroyAllWindows;
return 0;
}
So as the title says, i'm having a problem when working with opencv on c++ using interface of Windows forms only to send the input for the actions on the program, basically i save the treated images on a folder and recover them without any problem i even checked like a hundred times if there was any problem when i recover the images and no, there is nothing wrong there, so i started testing the output image that the program was giving and i realized that the reconstructed image taken from the FaceRecognizer was completely black, i tried to change the declarations but nothing changes, and what is funny is that this same algorith Works on another Project that i created as a testing and there is no interface there, only the console so the program is running on the main function, and in this testing Project when i reconstruct the image from the face FaceRecognizer it returns a normal face image and it recognize the correct face, but on the new Project with interface i use the same image as input and it recognizes all wrong and also reconstruct the black image, i think that is something wrong with the FaceRecognizer model but i have no idea what it is exactly! can anyone help me?
Here is the code to recover the images from the folder:
if (traiModel)
{
// read all folders on the images and for each one give an number id
// read the images for each folder and add on a vector of images
// read the folder name and give to all images to set the label info
Preprocessed_Faces.clear();
faceLabels.clear();
Preprocessed_Faces_Names.clear();
std::string folder = "TrainingFolder\\";
std::vector<cv::string> foldernames;
foldernames = get_all_files_names_within_folder(folder);
std::vector<int> labels;
for (int f = 0; f < foldernames.size(); f++)
{
std::string thisfoldername = folder + foldernames[f];
std::vector<cv::string> filenames;
cv::glob(thisfoldername, filenames);
Preprocessed_Faces_Names.push_back(foldernames[f]);
labels.push_back(f + 1);
for (int fn = 0; fn < filenames.size(); fn++)
{
Preprocessed_Faces.push_back(cv::imread(filenames[fn]));
//std::cout << filenames[fn] << std::endl;
faceLabels.push_back(f + 1);
}
}
cv::imwrite("Traintest.PNG", Preprocessed_Faces[0]);
std::map<int, std::string> map1;
for (int i = 0; i < Preprocessed_Faces_Names.size(); i++)
{
map1.insert(std::pair<int, std::string>(labels[i], Preprocessed_Faces_Names[i]));
std::cout << Preprocessed_Faces_Names[i] << std::endl;
}
model->setLabelsInfo(map1);
model->train(Preprocessed_Faces, faceLabels);
traiModel = false;
}
Here is the code for identify the face he tries to reconstruct the face first and identify:
if (identif)
{
// identify the current face looking on the database
// Prediction Validation
// Get some required data from the FaceRecognizer model.
cv::Mat eigenvectors = model->get<cv::Mat>("eigenvectors");
cv::Mat averageFaceRow = model->get<cv::Mat>("mean");
// Project the input image onto the eigenspace.
cv::Mat projection = cv::subspaceProject(eigenvectors, averageFaceRow, filtered.reshape(1, 1));
// Generate the reconstructed face back from the eigenspace.
cv::Mat reconstructionRow = cv::subspaceReconstruct(eigenvectors, averageFaceRow, projection);
// Make it a rectangular shaped image instead of a single row.
cv::Mat reconstructionMat = reconstructionRow.reshape(1, filtered.rows);
// Convert the floating-point pixels to regular 8-bit uchar.
cv::Mat reconstructedFace = cv::Mat(reconstructionMat.size(), CV_8U);
reconstructionMat.convertTo(reconstructedFace, CV_8U, 1, 0);
cv::imwrite("Teste.PNG", filtered);
cv::imwrite("Teste2.PNG", reconstructedFace);
int identity = model->predict(filtered);
double similarity = getSimilarity(filtered, reconstructedFace);
if (similarity > .7f)
{
//identity = -1; // -1 means that the face is not registred in the trainer
}
std::cout << "This is: " << identity << " and: " << model->getLabelInfo(identity) << std::endl;
identif = false;
}
here is the code where the complete loop for identifying a face runs and also the declaration of the FaceRecognizer the 2 odes above are in there:
void RecognitionAlgo::Running()
{
// Create the cascade classifier object used for the face detection
cv::CascadeClassifier face_cascade;
// Use the haarcascade frontalface_alt.xml library
if (!face_cascade.load("haarcascade_frontalface_alt.xml"))
{
Log("Error at face Cascade Load!")
}
// Setup image files used in the capture process
cv::Mat captureFrame;
cv::Mat grayscaleFrame;
cv::Mat shrinkFrame;
// Create a vector to store the face found
std::vector<cv::Rect> faces;
std::vector<cv::Mat> Preprocessed_Faces;
std::vector<cv::string> Preprocessed_Faces_Names;
cv::string myname;
std::vector<int> faceLabels;
// Init the face Recognizer
cv::initModule_contrib();
std::string facerecAlgorithm = "FaceRecognizer.Fisherfaces";
cv::Ptr<cv::FaceRecognizer> model;
// Use OpenCV's new FaceRecognizer in the "contrib" module;
model = cv::Algorithm::create<cv::FaceRecognizer>(facerecAlgorithm);
if (model.empty())
{
std::cerr << "ERROR: FaceRecognizer" << std::endl;
}
try
{
//model->load("TrainedModel.xml");
}
catch (const std::exception&)
{
}
// Create a loop to caoture and find faces
while (true)
{
// Capture a new image frame
if (swCamera)
{
captureDevice >> captureFrame;
}
else
{
captureFrame = cv::imread("face3.PNG");
}
// Shrink the captured image, Convert to gray scale and equalize
cv::cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
cv::equalizeHist(grayscaleFrame, grayscaleFrame);
shrinkFrame = ShrinkingImage(grayscaleFrame);
// Find faces on the shrink image (because it's faster) and store them in the vector array
face_cascade.detectMultiScale(shrinkFrame, faces, 1.1, 4, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
if (faces.size() > 0)
faces = EnlargeResults(captureFrame, faces);
// Draw a rectangle for all found faces in the vector array on original image
for (int i = 0; i < faces.size(); i++)
{
cv::Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
cv::Point pt2(faces[i].x, faces[i].y);
cv::Mat theFace = grayscaleFrame(faces[i]);
// try to treat the face by identifying the eyes, if the eyes fail to detect, it returns theface
cv::Mat filtered = TreatmentForFace(theFace);
// Collecting faces and learning from them.
if (starTraining && TrainName != "")
{
if (colFace)
{
Preprocessed_Faces.push_back(filtered);
if (myname == "")
{
myname = TrainName;
}
colFace = false;
}
}
else
{
if (!starTraining && Preprocessed_Faces.size() > 0)
{
// create the person folder
std::string command = "mkdir ";
std::string foldercom = "TrainingFolder\\" + myname;
command += foldercom;
system(command.c_str());
// create a string to access the recent created folder
std::string foldername = foldercom.substr(0, foldercom.size() - (myname.size() + 1));
foldername.append("/");
foldername.append(myname);
foldername.append("/");
foldername.append(myname);
// save the colected faces on the folder
for (int i = 0; i < Preprocessed_Faces.size(); i++)
{
std::ostringstream oss;
oss << i;
cv::imwrite(foldername + oss.str() + ".PNG", Preprocessed_Faces[i]);
}
myname = "";
Preprocessed_Faces.clear();
}
}
if (traiModel)
{
// read all folders on the images and for each one give an number id
// read the images for each folder and add on a vector of images
// read the folder name and give to all images to set the label info
Preprocessed_Faces.clear();
faceLabels.clear();
Preprocessed_Faces_Names.clear();
std::string folder = "TrainingFolder\\";
std::vector<cv::string> foldernames;
foldernames = get_all_files_names_within_folder(folder);
std::vector<int> labels;
for (int f = 0; f < foldernames.size(); f++)
{
std::string thisfoldername = folder + foldernames[f];
std::vector<cv::string> filenames;
cv::glob(thisfoldername, filenames);
Preprocessed_Faces_Names.push_back(foldernames[f]);
labels.push_back(f + 1);
for (int fn = 0; fn < filenames.size(); fn++)
{
Preprocessed_Faces.push_back(cv::imread(filenames[fn]));
//std::cout << filenames[fn] << std::endl;
faceLabels.push_back(f + 1);
}
}
cv::imwrite("Traintest.PNG", Preprocessed_Faces[0]);
std::map<int, std::string> map1;
for (int i = 0; i < Preprocessed_Faces_Names.size(); i++)
{
map1.insert(std::pair<int, std::string>(labels[i], Preprocessed_Faces_Names[i]));
std::cout << Preprocessed_Faces_Names[i] << std::endl;
}
model->setLabelsInfo(map1);
model->train(Preprocessed_Faces, faceLabels);
traiModel = false;
}
if (identif)
{
// identify the current face looking on the database
// Prediction Validation
// Get some required data from the FaceRecognizer model.
cv::Mat eigenvectors = model->get<cv::Mat>("eigenvectors");
cv::Mat averageFaceRow = model->get<cv::Mat>("mean");
// Project the input image onto the eigenspace.
cv::Mat projection = cv::subspaceProject(eigenvectors, averageFaceRow, filtered.reshape(1, 1));
// Generate the reconstructed face back from the eigenspace.
cv::Mat reconstructionRow = cv::subspaceReconstruct(eigenvectors, averageFaceRow, projection);
// Make it a rectangular shaped image instead of a single row.
cv::Mat reconstructionMat = reconstructionRow.reshape(1, filtered.rows);
// Convert the floating-point pixels to regular 8-bit uchar.
cv::Mat reconstructedFace = cv::Mat(reconstructionMat.size(), CV_8U);
reconstructionMat.convertTo(reconstructedFace, CV_8U, 1, 0);
cv::imwrite("Teste.PNG", filtered);
cv::imwrite("Teste2.PNG", reconstructedFace);
int identity = model->predict(filtered);
double similarity = getSimilarity(filtered, reconstructedFace);
if (similarity > .7f)
{
//identity = -1; // -1 means that the face is not registred in the trainer
}
std::cout << "This is: " << identity << " and: " << model->getLabelInfo(identity) << std::endl;
identif = false;
}
}
// Print the output
cv::resize(captureFrame, captureFrame, cv::Size(800, 600));
cv::imshow("outputCapture", captureFrame);
// pause for 33ms
cv::waitKey(33);
}
}
The OpenCV FaceRecognizer is implemented to be used with grayscale images. The problem is where you are reading the images from disk using cv::imread().
(cv::imread(filenames[fn]));
Even though you might have grayscale images saved, imread() by default loads 3 channel images. Specify CV_LOAD_IMAGE_GRAYSCALE as shown below.
(cv::imread(filenames[fn],CV_LOAD_IMAGE_GRAYSCALE));
I am developing some video analytic algorithms using openCV. However, after I process a frame and want to display it on a window, it hangs at imshow() function. I have searched for this issue online but still cannot find the problem! Here is the code where I am using multithread and openCV:
void CFeatureExtraction::extract(){
boost::thread OpFlowThread, BGSThread;
while (m_nRun){
ImgPtr frame_ptr;
m_pQueue->wait_and_pop(frame_ptr);
Mat frame1, frame2;
(*frame_ptr).copyTo(frame1);
(*frame_ptr).copyTo(frame2);
OpFlowThread = boost::thread(&COpFlow::op_flow, m_pAlgo,frame1);
BGSThread = boost::thread(&CBGSub::bgsub, m_pBGS, frame2);
OpFlowThread.join();
BGSThread.join();
}
}
And inside op_flow and bgsub function, I am using imshow() and cvWaitKey() together! But it keeps hanging the whole program.
If my question is still not clear for you, pls feel free to ask me for more detail.
Here is the detail code of calling imshow():
CFarnebackAlgo::CFarnebackAlgo() : COpFlow()
{
namedWindow("Optical Flow");
}
CFarnebackAlgo::~CFarnebackAlgo()
{
destroyWindow("Optical Flow");
}
int CFarnebackAlgo::op_flow(Mat frame)
{
Mat flow;
cvtColor(frame, gray, COLOR_BGR2GRAY);
if (prevgray.data)
{
calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
for (int y = 0; y < frame.rows; y += 8)
for (int x = 0; x < frame.cols; x += 8){
const Point2f& fxy = flow.at<Point2f>(y, x);
line(frame, Point(x, y), Point(cvRound(x + fxy.x), cvRound(y + fxy.y)), Scalar(0, 255, 0));
circle(frame, Point(x, y), 2, Scalar(0, 255, 0), -1);
}
if (frame.data == NULL){
cout << "No Img!" << endl;
exit(0);
}
imshow("Optical Flow", frame);
waitKey(50);
}
std::swap(prevgray, gray);
return 0;
}
If I put the namedWindow() in the op_flow(), it is working. But if I put it in the constructor, it's not working and freezes. Anyone knows why?
I'm trying to modify and write some video using openCV 2.4.6.1 using the following code:
cv::VideoCapture capture( video_filename );
// Check if the capture object successfully initialized
if ( !capture.isOpened() )
{
printf( "Failed to load video, exiting.\n" );
return -1;
}
cv::Mat frame, cropped_img;
cv::Rect ROI( OFFSET_X, OFFSET_Y, WIDTH, HEIGHT );
int fourcc = static_cast<int>(capture.get(CV_CAP_PROP_FOURCC));
double fps = 30;
cv::Size frame_size( RADIUS, (int) 2*PI*RADIUS );
video_filename = "test.avi";
cv::VideoWriter writer( video_filename, fourcc, fps, frame_size );
if ( !writer.isOpened() && save )
{
printf("Failed to initialize video writer, unable to save video!\n");
}
while(true)
{
if ( !capture.read(frame) )
{
printf("Failed to read next frame, exiting.\n");
break;
}
// select the region of interest in the frame
cropped_img = frame( ROI );
// display the image and wait
imshow("cropped", cropped_img);
// if we are saving video, write the unwrapped image
if (save)
{
writer.write( cropped_img );
}
char key = cv::waitKey(30);
When I try to run the output video 'test.avi' with VLC I get the following error: avidemux error: no key frame set for track 0. I'm using Ubuntu 13.04, and I've tried using videos encoded with MPEG-4 and libx264. I think the fix should be straightforward but can't find any guidance. The actual code is available at https://github.com/benselby/robot_nav/tree/master/video_unwrap. Thanks in advance!
[PYTHON] Apart from the resolution mismatch, there can also be a frames-per-second mismatch. In my case, the resolution was correctly set, but the problem was with fps. Checking the frames per second at which VideoCapture object was reading, it showed to be 30.0, but if I set the fps of VideoWriter object to 30.0, the same error was being thrown in VLC. Instead of setting it to 30.0, you can get by with the error by setting it to 30.
P.S. You can check the resolution and the fps at which you are recording by using the cap.get(3) for width, cap.get(4) for height and cap.get(5) for fps inside the capturing while/for loop.
The full code is as follows:
import numpy as np
import cv2 as cv2
cap = cv2.VideoCapture(0)
#Define Codec and create a VideoWriter Object
fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
#30.0 in the below line doesn't work while 30 does work.
out = cv2.VideoWriter('output.mp4', fourcc, 30, (640, 480))
while(True):
ret, frame = cap.read()
colored_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
print('Width = ', cap.get(3),' Height = ', cap.get(4),' fps = ', cap.get(5))
out.write(colored_frame)
cv2.imshow('frame', colored_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
The full documentation (C++) for what all properties can be checked is available here : propId OpenCV Documentation
This appears to be an issue of size mismatch between the frames written and the VideoWriter object opened. I was running into this issue when trying to write a series of resized images from my webcam into a video output. When I removed the resizing step and just grabbed the size from an initial test frame, everything worked perfectly.
To fix my resizing code, I essentially ran a single test frame through my processing and then pulled its size when creating the VideoWriter object:
#include <cassert>
#include <iostream>
#include <time.h>
#include "opencv2/opencv.hpp"
using namespace cv;
int main()
{
VideoCapture cap(0);
assert(cap.isOpened());
Mat testFrame;
cap >> testFrame;
Mat testDown;
resize(testFrame, testDown, Size(), 0.5, 0.5, INTER_NEAREST);
bool ret = imwrite("test.png", testDown);
assert(ret);
Size outSize = Size(testDown.cols, testDown.rows);
VideoWriter outVid("test.avi", CV_FOURCC('M','P','4','2'),1,outSize,true);
assert(outVid.isOpened());
for (int i = 0; i < 10; ++i) {
Mat frame;
cap >> frame;
std::cout << "Grabbed frame" << std::endl;
Mat down;
resize(frame, down, Size(), 0.5, 0.5, INTER_NEAREST);
//bool ret = imwrite("test.png", down);
//assert(ret);
outVid << down;
std::cout << "Wrote frame" << std::endl;
struct timespec tim, tim2;
tim.tv_sec = 1;
tim.tv_nsec = 0;
nanosleep(&tim, &tim2);
}
}
My guess is that your problem is in the size calculation:
cv::Size frame_size( RADIUS, (int) 2*PI*RADIUS );
I'm not sure where your frames are coming from (i.e. how the capture is set up), but likely in rounding or somewhere else your size gets messed up. I would suggest doing something similar to my solution above.
I am using a Mac OS X 10.6 machine. I have OpenCV 2.1 x64 compiled from source using Xcode and its GCC compiler.
I am having trouble using the C++ video reading features of OpenCV. Here is the simple test code I am using (came straight from OpenCV documentation):
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(200) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
The program compiles fine, but when I try to run it, I see the green light on my webcam come on for a few seconds, then the program exits with the error message:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /Users/mark/Downloads/OpenCV-2.1.0/src/cxcore/cxarray.cpp, line 2476
terminate called after throwing an instance of 'cv::Exception'
what(): /Users/mark/Downloads/OpenCV-2.1.0/src/cxcore/cxarray.cpp:2476: error: (-206) Unrecognized or unsupported array type in function cvGetMat
Under debug mode, the matrix still seems to be empty after the cap >> frame line.
I get similar behavior when I try to capture from a video file or an image, so it's not the camera. What is wrong, do you think? Anything I can do to make this work?
EDIT: I'd like to add that if I use the C features, everything works fine. But I would like to stick with C++ if I can.
Thanks
I've seen the same problem. When I use the C features, sometimes the similar question also comes up. From the error message of the C code, I think it happened because the camera got a NULL frame. So I think it can be solved in this way:
do
{
capture>>frame;
}while(frame.empty());
That way it works on my machine.
I encountered the same problem, it seems that the first two attempts to get the video wont return any signal, so if you try to use it you'll get an error, here is how I got around this, simply by adding a counter and checking the size of the video.
int cameraNumber = 0;
if ( argc > 1 )
cameraNumber = atoi(argv[1]);
cv::VideoCapture camera;
camera.open(cameraNumber);
if ( !camera.isOpened() ) {
cerr << "ERROR: Could not access the camera or video!" << endl;
exit(1);
}
//give the camera 40 frames attempt to get the camera object,
//if it fails after X (40) attemts the app will terminatet,
//till then it will display 'Accessing camera' note;
int CAMERA_CHECK_ITERATIONS = 40;
while (true) {
Mat cameraFrame;
camera >> cameraFrame;
if ( cameraFrame.total() > 0 ) {
Mat displayFrame( cameraFrame.size(), CV_8UC3 );
doSomething( cameraFrame, displayFrame );
imshow("Image", displayFrame );
} else {
cout << "::: Accessing camera :::" << endl;
if ( CAMERA_CHECK_ITERATIONS > 0 ) CAMERA_CHECK_ITERATIONS--;
if ( CAMERA_CHECK_ITERATIONS < 0 ) break;
}
int key = waitKey(200);
if (key == 27) break;
}
Try simplifying the program so that you can identify the exact location of the problem, e.g. change your loop so that it looks like this:
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
// cvtColor(frame, edges, CV_BGR2GRAY);
// GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
// Canny(edges, edges, 0, 30, 3);
// imshow("edges", edges);
imshow("edges", frame);
if(waitKey(200) >= 0) break;
}
If that works OK then try adding the processing calls back in, one at a time, e.g
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
// GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
// Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(200) >= 0) break;
}
and so on...
Once you've identified the problematic line you can then focus on that and investigate further.
Go to project->project properties->configuration properties->linker->input
In the additional dependencies paste cv210.lib cvaux210.lib cxcore210.lib highgui210.lib
Hi I got the solution for you :)
VideoCapture san_cap(0);
if (san_cap.isOpened()) {
while (1) {
san_cap.read(san);
imshow("Video", san);
Mat frame;
san_cap.read(frame); // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
imshow("Video2", edges);
int key = cv::waitKey(waitKeyValue);
if (key == 27 ) {
break;
}
}
}