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
Related
I use opencv2.4.9 whith visual studio 2010
when I have to show an image program display the empty window and not show image
and its my code:
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\core\core.hpp>
#include<opencv\cv.h>
int main(int argc,char**argv[]) {
IplImage* img1=cvLoadImage("C:\opencv\sources\samples\cpp\board.jpg");
cvNamedWindow("img1",CV_WINDOW_AUTOSIZE);
cvShowImage("img1",img1);
cvWaitKey(0);
cvReleaseImage(&img1);
}
The problem is in the way you wrote the path of the image. you should not use the escape character alone. You can solve it by one of these:
IplImage* img1=cvLoadImage("C:\\opencv\\sources\\samples\\cpp\\board.jpg");
Or:
IplImage* img1=cvLoadImage("C:/opencv/sources/samples/cpp/board.jpg");
Or:
IplImage* img1=cvLoadImage(R"(C:\opencv\sources\samples\cpp\board.jpg)");
BTW, you are using C interface which is really too out of data. If you do not have a REAL reason to use it, please do not. The equivalent code that use C++ is:
int main(int argc,char**argv[]) {
cv::Mat img1=cv::imread("C:\\opencv\\sources\\samples\\cpp\\board.jpg");
cv::namedWindow("img1",CV_WINDOW_AUTOSIZE);
cv::imshow("img1",img1);
cv::waitKey(0);
//No need to release manually
}
if you use Mat then you can use:
if (frame1.empty())
{
std::cout << "no image";
break;
}
then if the image not empty you should use more delay to display the images.
for example you can use:
waitKey(100);
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;
}
I am trying to detect faces using the below code making use of GPU
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <iostream>
#include <stdio.h>
#include <opencv2\ocl\ocl.hpp>
std::string face_cascade = "C:\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt.xml";
std::vector<cv::Rect> detectFaces(cv::Mat gray){
cv::ocl::oclMat oclGray;
std::vector<cv::Rect> faces;
cv::ocl::OclCascadeClassifier face_detector;
oclGray.upload(gray);
face_detector.load(face_cascade);
face_detector.detectMultiScale(oclGray, faces, 1.1, 3, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30), cv::Size(0, 0));
return faces;
}
int main(){
cv::VideoCapture webcam;
cv::Mat mainImage;
std::vector<cv::Rect> faces;
webcam.open(0);
cv::namedWindow("face",CV_WINDOW_AUTOSIZE);
while(webcam.isOpened()){
webcam.read(mainImage);
if(!mainImage.empty()){
cv::resize(mainImage,mainImage,cv::Size(640,480),0,0,1);
cv::Mat gray(mainImage);
cv::cvtColor(gray,gray,CV_BGR2GRAY);
cv::equalizeHist(gray,gray);
faces = detectFaces(gray);
for(unsigned int i=0;i<faces.size();i++){
cv::Rect f_rect = faces[i];
cv::rectangle(mainImage,f_rect,CV_RGB(255,0,0),1,8,0);
}
cv::imshow("face",mainImage);
}
cv::waitKey(40);
}
return 0;
}
I wasnt satisfied with t speed of the normal cascade classifier and thus coded for Ocl based classifier. The program gets started but shows error message:
I have installed APP SDK v 2.9.1
I am using Visual Studio 2012 express edition, Opencv 2.4.10
Where did I go wrong??
Thanks
EDIT>>
cv::ocl::oclMat oclGray;
oclGray.upload(gray);
The above code is causing error..
It looks like it fails on this line face_detector.load(face_cascade); (use debugger to make sure that i'm right). Make sure that the path is correct and that format of cascade file is valid, you may try to use different cascade as well and of course make sure that OCL is installed and configured correctly.
I have searched a lot about my simple problem but I didn't find solution. When I run my code black console shows me the camera frame size but in the window video is not showing, it shows a solid gray screen. But if I play a video from HDD then it works fine.
Please help me some one.
This is my code
#include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
int main(int argc, char** argv){
CvCapture *capture;
IplImage* img=0;
cvNamedWindow("Window");
capture = cvCreateCameraCapture( -1);
//capture = cvCaptureFromAVI("1.mp4");
//capture = cvCaptureFromCAM(-1);
int ext=0;
assert( capture );
if(capture==NULL){
cout<<"Cam Not Found!!!"<<endl;
getchar();
return -5;
}
while ( true ){
img = cvQueryFrame( capture );
cvSaveImage("1.jpg",img);
if (!img){
printf("Image not Found\n");
break;
}
cvShowImage("Window", img);
cvWaitKey(50);
}
cvReleaseImage(&img);
cvDestroyWindow("Window");
cvReleaseCapture(&capture);
return 0;
}
I use opencv 2.2 and Visual studio 2010
One thing is obviouslly wrong, you need to change the order of the calls to:
cvShowImage("Window", img);
cv::waitKey(20);
Second, it's essential that you check the success of cvQueryFrame():
img = cvQueryFrame( capture );
if (!img)
{
// print something
break;
}
EDIT:
By the way, I just noticed you are mixing the C interface of OpenCV with the C++ interface. Don't do that! Replace cv::waitKey(50); by cvWaitKey(50);.
For debugging purposes, if cvQueryFrame() succeeds I suggest you store one frame to the disk with cvSaveImage(), and if that image is OK it means the capture procedure is actually working perfectly and the problem is somewhere else.
I jast switch the openCV version 2.2 to 2.1 and its work perfectly.......
I am using OpenCV version 3.1, I got the same problem, I re-built openCV 3.1 and re-checked Environment Variables, so my problem resolved. You can back-up built-opencv and extract if you need. Sorry for my bad english :)
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.