I am new to OpenCV I was trying to read image in visual studio 2012 but was not able to load image using imshow but it works fine when I use cvLoadImage.
When I execute the following code it works fine but
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
//char key;
int main()
{
IplImage *image = cvLoadImage("test1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cvNamedWindow("hah", WINDOW_AUTOSIZE);
cvShowImage("hah", image);
waitKey(5000);
return 1;
}`
but when I write the following code it throws an exception and image does not renders
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
//char key;
int main()
{
Mat image = imread("test1.jpg");
namedWindow("My");
imshow("My", image);
waitKey(50000);
return 1;
}
I am not able to understand what is the problem.
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'm trying to display an image 123.jpg on the screen, the display view did show up but the image didn't and the program exits with status 255
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat image;
image = cv::imread("123.jpg", CV_LOAD_IMAGE_UNCHANGED);
namedWindow("displayWindow", CV_WINDOW_AUTOSIZE);
imshow("displayWindow", image);
waitKey(0);
return 0;
}
Is there a problem in the code ?
error
error
not sure how to proceed... still wet behind the ears, looking for advice.
//"strange" error using eclipse and opencv while following along in API
./src/captureCV.o: undefined reference to symbol '_ZN2cv12GaussianBlurERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi'
and here's the cpp:
/*
* captureCV.cpp
*/
#include "opencv2/opencv.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <string.h>
#include <stdio.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(30) >= 0) break;
}
return 0;
}
not much to see just sample API material taken from openCV
build exits after executable is made.
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.