#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv2\videoio.hpp>
using namespace cv;
int main(){
Mat image;
VideoCapture cap;
cap.open(0);
namedwindow("window",1);
while(1){
cap>>image;
imshow("window",image);
waitKey(33);
}
return 0;
}
when i try to run the program above i get the error that identifiers "namedWindow", "imshow" and "waitkey" are undefined.
i am coding in visual studio 2010.
You're including obsolete C code. To include the correct headers, use opencv2 and correct path.
Note that you can avoid all these includes, using the include all: #include <opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/video/video.hpp>
// or use only: #include <opencv2/opencv.hpp>
using namespace cv;
int main(){
Mat image;
VideoCapture cap;
cap.open(0);
namedWindow("window", 1);
while (1){
cap >> image;
imshow("window", image);
waitKey(33);
}
return 0;
}
if you use
#include<opencv\cv.h>
#include<opencv\highgui.h>
you have to use different, C functions, like cvNamedWindow("title"); and cvShowImage("title", img);
Use the following C++ includes:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2\opencv.hpp>
(you dont'h have to use all of them ...)
Related
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat srcImage = imread(img_path, CV_LOAD_IMAGE_UNCHANGED);
imwrite("./test.png", srcImage);
return 0;
}
i read a image,then save to file.but the image color is changed.this is why??
compare of src&dst image
I am using opencv 3.3.0
my code is
#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <fstream>
#include <string>
#include <vector>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main(int argc, char** argv)
{
Mat img1;
img1 = imread("img/img1.jpg", IMREAD_GRAYSCALE);
if (img1.empty())
{
cout << "Could not open or find the image" << endl;
return -1;
}
Ptr<SurfFeatureDetector> detector = SurfFeatureDetector::create(400);
vector<KeyPoint> keypoints;
detector->detect(img1, keypoints);
imshow("img1", img1);
waitKey(0);
return 0;
}
I am new to C++ and opencv. The code work well without surf part.
error
OpenCV Error: Assertion failed (TlsSetValue(tlsKey, pData) == TRUE) in cv::TlsAbstraction::SetData, file C:\Users\Darshana\Documents\opencv\opencv-3.3.0\modules\core\src\system.cpp, line 1270
I have tried with Ptr<SURF> detector = SURF::create(400); as well.
UPDATE
I couldn't figure out a solution for this. Maybe a setup issue or library issue. So I just move to opencv 2.4.13 and now everything works fine. I had to change the above code to work with v2.4.13 though.
You haven't set parameter for SurfFeatureDetector. I think you should try this instead:
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints;
detector.detect(img1, keypoints);
I am kind of an intermediate in Computer Vison and fairly proficient in opencv python however coming to c++ i am facing problems in just selecting ROI from Video feed and displaying the cropped feed .My code looks like this.
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/tracking.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main() {
Mat frame1;
VideoCapture cap;
cap.open(0);
cap.read(frame1);
Rect2d roi = selectROI(frame1, true);
Mat Crop = frame1(roi);
while (1) {
cap.read(frame1);
Crop = frame1(roi);
if (Crop.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
imshow("roi", Crop);
int key=waitkey(0);
}
}
The code is compiling ,and the cropped window is seen however I am always in need to click enter,spacebar or esc to get the video feed.Weird?
So the correct version of the corrected code will look somewhat like this.Thanks for the help.
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/tracking.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main() {
Mat frame1;
VideoCapture cap;
cap.open(0);
cap.read(frame1);
Rect2d roi = selectROI(frame1, true);
Mat Crop = frame1(roi);
while (1) {
cap.read(frame1);
Crop = frame1(roi);
if (Crop.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
imshow("roi", Crop);
*int key=waitkey(1)*;
}
}
Which OpenCV's function support the analog camera for live streaming?
Please give me the answer.
I tried CvCapture and VideoCapture functions of OpenCV.
It works for USB camera but did not work for Analog camera.
I tried VideoInput function.It works well with analog camera but i want opencv inbuilt function.
So please help me.
Thanks for your time.
This is the code for cvcapture function which I have used.
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
char key;
int main()
{
cvNamedWindow("Camera_Output", 1); //Create window
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system
while(1){ //Create infinte loop for live streaming
IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
cvShowImage("Camera_Output", frame); //Show image frames on created window
key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27){
break; //If you hit ESC key loop will break.
}
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
return 0;
}
end of code
Next code is using VideoInput function.
The code is
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int, char**)
{
videoInput VI;
int numDevices = VI.listDevices();
//int device1= 0;
VI.setup(0);
unsigned char* yourBuffer = new unsigned char[VI.getSize(0)];
IplImage* colourImage = cvCreateImage(cvSize(320,240),8,3);
while(1)
{
VI.grabFrame(0, yourBuffer);
colourImage->imageData = (char*)yourBuffer;
cvConvertImage(colourImage, colourImage, 3);
cvShowImage("test",colourImage);
if( cvWaitKey(10) == 27)
break;
}
return 0;
}
end of code
and last code is using videocapture function
the code is
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main() {
VideoCapture stream1(-1); //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";
return 0;
}
//unconditional loop
while (true) {
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
End of code
Please help me.
I am trying to execute the following program using openCV 2.4.3 on Ubuntu 12.04 LTS.
But I get "camera not initialized as the output" Can anybody help me.
here is the code:
include <iostream>
include "opencv2/imgproc/imgproc.hpp"
include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap(1);
if (!cap.isOpened())
{
cout <<"Failed to initialize camera\n";
return 1;
}
namedWindow("CameraCapture");
Mat frame;
while (1)
{
cap>> frame;
imshow("cameraCapture",frame);
if (waitKey(30)>0)break;
}
destroyAllWindows();
return 0;
}
Please help me!
Thanks,
Kushal
try the following...
#include "iostream"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
CvCapture *webcam = cvCaptureFromCAM(-1);
IplImage *img = NULL;
while(true)
{
img = cvQueryFrame(webcam);
cvShowImage("TEST",img);
cvWaitKey(20);
}
return 0;
}
did u check the default capture device? by default it is 0
VideoCapture cap(0);