I'm new to OpenCV.
I've given a link to the function imread as follows:
Mat logo = imread("http://files.kurento.org/img/mario-wings.png");
I've checked and the image exists on the given path. imread() still fails to read it.
Any mistake that I've made?
-Thanks
In fact imread is not able to read image data via http.
But it's possible using VideoCapture.
See this little snippet:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
cv::VideoCapture vc;
vc.open("http://files.kurento.org/img/mario-wings.png");
if(vc.isOpened() && vc.grab()) {
cv::Mat logo;
vc.retrieve(logo);
cv::namedWindow("t");
cv::imshow("t", logo);
cv::waitKey(0);
vc.release();
}
return 0;
}
Related
Im using a Basler camera, and I'm trying to save the grabbed image with OpenCV. However, when i try to use imwrite(), I get this error:
imwrite_('C:/Users/Uporabnik/Desktop/slika.png'): can't write data: unknown exception
My conversion of the grabbed image:
openCvImage = Mat(image.GetHeight(), image.GetWidth(), CV_16U, (uint8_t *)image.GetBuffer());
Trying to save the image:
cv::imwrite("C:/Users/Uporabnik/Desktop/slika.png", openCvImage);
I am also using basler camera. You also need to share codes which includes basler configurations.Here is how I used basler camera to get frame in the format of opencv:
#include <pylon/usb/BaslerUsbInstantCamera.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <pylon/PylonIncludes.h>
using namespace std;
using namespace cv;
using namespace Pylon;
using namespace GenApi;
using namespace Basler_UsbCameraParams;
int main()
{
Mat openCvImage;
Pylon::PylonAutoInitTerm autoInitTerm;
CBaslerUsbInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());
CImageFormatConverter formatConverter;
CPylonImage pylonImage;
camera.MaxNumBuffer = 1;
formatConverter.OutputPixelFormat= PixelType_BGR8packed;
camera.StartGrabbing( c_countOfImagesToGrab);
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
formatConverter.Convert(pylonImage, ptrGrabResult);
openCvImage= cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult>GetWidth(), CV_8UC3, (uint8_t *) pylonImage.GetBuffer());
imshow("Basler Frame",openCvImage);
waitKey(0);
return 0;
}
But first of all you need to use "imshow" function to see image.
If you can, the problem is in your directory part. Otherwise you need to share code about initiating basler camera.
Please just pay attention to the dimension of your image, you can simply print and see if the shape is correct. In my case, I include the batchsize dimension to the image shape by mistake, and I solve it by image = image[0].
I am new to OpenCV. I appreciate if somebody answers this question. I try to read an image and display it. Below is a copy of the code I copied from documentation. However, a window just pops up without the actual image:
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("myimage.jpg", CV_LOAD_IMAGE_UNCHANGED);
if (img.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
else
{
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(5000);
}
return 0;
}
I have copied over your code, and changed the image to my local one, and it displays correctly.
Looks like the program cannot read the image for some reason.
Why don't you try with the full path to the image?
The code is pretty correct, make sure you got myimage.jpg in the same folder with your binary.
Try with full path to an image or provide a path to your image as argv[1].
I'm trying to use this function:
fastNlMeansDenoising(image, image, 3.0, 7, 21);
Using OpenCV with Visual Studio 2010 express, but it said "identifier not found".
I did a quick search and found that this must be a ".lib" is missing, but I did not find which library should I add in my project for this function to work. Anyone could help me with this?
Ok. In order to use fastNlMeansDenoising(image, image, 3.0, 7, 21);
1) You need to configure opencv 2.4.8 or 2.4.9.
Here is procedure to link opencv 249 with Visual studio.
2) Use the following code to test opencv function
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
// load the image
Mat img = imread("lenna.jpg");
if(!img.data)
{
cout << "File not found" << endl;
return -1;
}
// show it in a window
namedWindow( "Image", WINDOW_AUTOSIZE );
imshow("Image", img);
// image window will immediately disappear if the program ends, so
// we'll wait for a keypress, indefinitely
waitKey();
// do a simple transformation: convert to grayscale
// first copy the image
Mat img_gray = img.clone();
Mat img1;
cvtColor(img, img_gray, CV_RGB2GRAY);
fastNlMeansDenoising(img_gray,img1,3.0,7,21);
imshow("Image", img1);
waitKey();
return 0;
}
Hope, this helps you.
Cheers,
The function is defined in the photo.hpp file. So you have to get the opencv_photo300.lib
Edit 1:
I searched a little bit (sorry im at work, dont have more time) and i couldnt find the library itself. You can go ahead and build opencv yourself from: https://github.com/Itseez/opencv
Then you can just search that folder for the lib.
An installationguide for the build process is here: http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html
Edit 2:
Berak is right, the opencv_photo300.lib is not in the 2.3 Version of OpenCV. Update your OpenCV to the current version 2.4.9 and you'll have what you need.
you will have to use opencv 2.4.9, it is not available in 2.3.0
I wrote a simple program in OpenCV that detects SURF feature in a given image and diplays the detected features in a namedWindow.
#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\features2d\features2d.hpp>
using namespace cv;
int main(int argc,char** argv)
{
if(argc!=3)//Check cmd number of argumets
{
std::cout<<"Usage: "<<argv[0]<<" <image-file> <method>"<<std::endl;
return -1;
}
//LOAD THE SOURCE IMAGE
Mat Img = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
if(!Img.data)//Check correct image load
{
std::cout<<"Cannot read image file. Check file path!"<<std::endl;
return -1;
}
//COMPUTE FEATURES
SurfFeatureDetector detector;
std::vector<KeyPoint> features;
detector.detect(Img,features);
//SHOW RESULT
Mat ImgF;
drawKeypoints(Img,features,ImgF);
namedWindow("Features", CV_GUI_NORMAL);
imshow("Features",ImgF);
waitKey();
return 0;
}
Everything is OK, the programs do what it have to do. The problem is when pressing a key to terminate the program a crash error occurs.
It doesn't crash for me... but in order for me to compile your code, I had to add
#include <opencv2/nonfree/features2d.hpp>
because SURF was moved to the nonfree module at some point.
So, I would have to recommend trying the newest version (2.4.6 as of today).
Im using Opencv 2.3.1 on Visual studio 2010 (vc10)
I have configured opencv based on many tutorials and can compile & run C-syntax program like:
#include "StdAfx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main ()
{
IplImage* img = cvLoadImage("D:\cat_helmet.jpg", CV_LOAD_IMAGE_UNCHANGED);
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
However, I cannot run the C++ syntax program like
#include "StdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
Mat image;
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
imshow( "Display window", image );
waitKey(0);
return 0;
}
I got the error messages (in the function calls: namedWindow, imread, imshow)
First-chance exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
Unhandled exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
How can I fix this?
You say that you have followed a multitude of guides and tutorials. I've had great success with this one
http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/
The thing is that this guy walks you through the 'park' and helps you unravel two major issues whilst setting up OpenCV 2.3.1; one of which is placement of .dll files in your project folder. The other is a missing .dll 'tbb_debug.dll' (the absense of this .dll is considered a bug in OpenCV 2.3.1).
He also provides some decent code-snippets for your to try out (in c++ syntax).
Good luck.
The above mentioned answers doesn't make sense. I am also facing the same problem. The main reason for this exception is that you are trying to display image (read by imread) which is empty. The main problem in the program is the line
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
I think imread function is not behaving the way it is expected. One more thing, while going through the references i came across a following link:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
Here, imread is used via call by reference method. I am not a C++ expert, but i feel it could be the problem.
int main()
{
std::string imgPath("splash.bmp"); //Add your file name
Mat img = imread(imgPath);
namedWindow( "Example1", WINDOW_AUTOSIZE);
imshow("Example1", img);
waitKey(0);
return 0;
}
This code worked for me. Also, I put the file next to executable to decrease complexity.