error C3861: 'getGaborKernel': identifier not found - c++

I am trying to build the following code, but It failed because of the following error
error C3861: 'getGaborKernel': identifier not found
I have included the required header files and lib files. What could be the problem?
#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <math.h>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
Mat in = imread("1.jpg",0); // load grayscale
Mat dest;
Mat src_f;
in.convertTo(src_f,CV_32F);
extern ostream cerr;
int kernel_size = 31;
double sig = 1, th = 0, lm = 1.0, gm = 0.02, ps = 0;
cv::Mat kernel =
getGaborKernel(cv::Size(kernel_size,kernel_size),sig, th, lm, gm,
ps);
cv::filter2D(src_f, dest, CV_32F, kernel);
cerr << dest(Rect(30,30,10,10)) << endl; // peek into the data
Mat viz;
dest.convertTo(viz,CV_8U,1.0/255.0);
imshow("k",kernel);
imshow("d",viz);
waitKey();
return 0;
}

When C++ misses a prototype it issues an error. Your source obviously didn't include the header file with the appropriate prototype or the prototype is hidden by #ifdefs.
Lookup the Header file that you expect that it contains the prototy of getGaborKernel.
Check the option Show includes to see what header files are actually included. Verify the header found in the first step is in the list.
Check the option Preprocess to a file to see what the preprocessor outputs after processing all #ifdefs in the generated .i file. Check why the prototype isn't in the output.
Uncheck both options after you have found the problem. That's important for the Preprocess to a file option to get a .obj file instead of the .i.

Related

Done building project "Project.vcxproj" -- FAILED

I wrote some lines of code to simply read and write an image and it was working a few days ago, but now Visual Studio gives these errors: "1>Done building project "Lab1_PI.vcxproj" -- FAILED." and it says it was "unable to start the program" and that the system cannot find the file specified.
I also tried to add add _CRT_SECURE_NO_DEPRECATE and _CRT_SECURE_NO_WARNINGS via right-click project->C/C+±>Preprocessor->Preprocessor Definitions, but nothing changed.
Also, here's my code, but it is correct since it was working a few days ago:
#include <iostream>
#include <string>
#include "opencv2\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
using namespace cv;
using namespace std;
int main(int arc, const char** argv) {
string imgPath = argv[1];
string img2Path = argv[2];
cv::Mat img = imread(imgPath);
if (!img.data) {
cout << "error:no image" << endl;
return -1;
}
imshow("flower image (color)", img);
Mat img2;
cvtColor(img, img2, COLOR_RGB2GRAY);
imwrite(img2Path, img2);
imshow("flower image (grey)", img2);
waitKey(0);
}
I would be really grateful if someone could help me fix this problem because it stops me from using Visual Studio and I really need it for a project!

error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'

I am new to C++ and i am getting error like
error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'
FaceDetector fd(string(DEFAULT_CASCADE_PATH));
and i am attaching my code and error log how to fix this please guide me
#define DEFAULT_CASCADE_PATH "cascades/haarcascade_frontalface_default.xml"
#define ORIGINALS_LIST "obama_raw/list"
#define OUTPUT_DIR "obama_faces"
#define OUTPUT_LIST "list"
#define FACE_SIZE Size(150,150)
#include <cstdlib>
#include <fstream>
#include "cv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "FaceDetector.h"
using namespace std;
using namespace cv;
void read_input_list(const string &list_path, vector<Mat> &images) {
ifstream file(list_path.c_str());
string path;
while (getline(file, path)) {
images.push_back(imread(path));
}
}
int main(int argc, char** argv) {
FaceDetector fd(string(DEFAULT_CASCADE_PATH));
vector<Mat> raw_faces;
ofstream out_list(format("%s/%s", OUTPUT_DIR, OUTPUT_LIST).c_str());
read_input_list(string(ORIGINALS_LIST), raw_faces);
int img_c = 0; //images counter
//now detect the faces in each of the raw images:
for (vector<Mat>::const_iterator raw_img = raw_faces.begin() ; raw_img != raw_faces.end() ; raw_img++){
vector<Rect> faces;
//detect faces in the image (there should be only one):
fd.findFacesInImage(*raw_img, faces);
//cut each face and write to disk:
for (vector<Rect>::const_iterator face = faces.begin() ; face != faces.end() ; face++){
int edge_size = max(face->width, face->height);
Rect square(face->x, face->y, edge_size, edge_size);
Mat face_img = (*raw_img)(square);
//resize:
resize(face_img, face_img, FACE_SIZE);
//write to disk:
string face_path = format("%s/%d.jpg", OUTPUT_DIR, img_c++);
imwrite(face_path,face_img);
out_list << face_path << endl;
}
}
out_list.close();
return 0;
}
and i am attaching my error log.Please can any one help.
Thanks in advance
Error : https://i.stack.imgur.com/RZXXK.jpg
From GCC 5, A new ABI is enabled by default. In that new ABI, std::__cxx11 namesapce was introduced.
According to your error message, It seems that your program and OpenCV library you want to link with were build with different GCC version, which made incompatible binary.
For more information, you can read the following page:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

OpenCV FeatureDetector is not initialized

I am trying to create a class where I shall find KeyPoints in an image. However, I get a ridiculous error I cannot figure out how to solve.
The problem is now that
this->detector
is zero, so it is for some reason not initialized properly. I have searched on google but I haven't found anything.
My headerfile looks as follows
/*
* FindKeyPoints.h
*
* Created on: Jan 21, 2015
* Author: erikbylow
*/
#ifndef FINDKEYPOINTS_H_
#define FINDKEYPOINTS_H_
#include <vector>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
using namespace std;
class FindKeyPoints {
private:
// Create vector of KeyPoints to store the detected keypoint in
vector<cv::KeyPoint> keyPointsOld;
vector<cv::KeyPoint> keyPointsNew;
// Threshold for similarity
const int THRESHOLD = 10;
// Instance(?) DescriptionExtractor and descriptor
cv::Ptr<cv::DescriptorExtractor> descriptionExtractor;
cv::Ptr<cv::FeatureDetector> detector;
public:
FindKeyPoints(const string &METHOD);
virtual ~FindKeyPoints();
void detectKeypoints(cv::Mat& imgNew, cv::Mat& imgOld);
};
#endif /* FINDKEYPOINTS_H_ */
And constructor looks as
FindKeyPoints::FindKeyPoints(const string &METHOD) {
cout<<METHOD<<endl;
cv::initModule_features2d();
this->detector = cv::FeatureDetector::create("SURF");
//this->descriptionExtractor = cv::DescriptorExtractor::create(METHOD);
}
and a function I will use looks as:
// Input: The new image and the old image. Find Keypoints and extract the descriptors.
void FindKeyPoints::detectKeypoints(cv::Mat& imgNew,
cv::Mat& imgOld) {
if (this->detector == 0){
cout<<"Hej"<<endl;
}
// this->detector->detect(imgNew, keyPointsNew);
// this->detector->detect(imgOld, keyPointsOld);
}
I use cmake and (part of) my CMakeLists.txt looks like:
TARGET_LINK_LIBRARIES(${PROJECT_NAME} groundtruth ${OpenCV_LIBS} ${QT_LIBRARIES}
${QGLViewer_LIBRARIES} ${OPENGL_gl_LIBRARY} GL
glut)
Can it be that
${OpenCV_LIBS}
does not include libopencv_nonfree.so ?
Regards
I suspect the error is that I had only included
opencv2/nonfree/features2d.hpp
and not also
opencv2/nonfree/nonfree.hpp.

Linking error in OpenCV programs when using third party libraries

I am trying to use graph library using opencv.
This is the code that I have written , and am building this on Visual studio 2010.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "GraphUtils.h"
using namespace cv;
using namespace std;
int main()
{
float floatArray[4]= {1,1,2,2};
showFloatGraph("Rotation Angle", floatArray, 4 );
return 0;
}
There is no compilation error.
However, I am getting following linking error:
Error 1 error LNK2019: unresolved external symbol _showFloatGraph
referenced in function _main C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\opencv1\helloworld.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\Debug\opencv1.exe
I have put the two files (GraphUtils.h and GraphUtils.c) with my .cpp file.
Why I am getting these compilation errors whenever I am using third party libraries (.c and .h) files, since I get this linking error also when using other library. I asked the question here
In Properties=>Linker=>input=>Additional dependencies , I have added :
opencv_core231d.lib;opencv_highgui231d.lib;opencv_imgproc231d.lib;opencv_features2d231d.lib;opencv_calib3d231d.lib;%(AdditionalDependencies)
And in fact my basic opencv program for image display works fine.
Do I need to do something special when using these libraries. As of now I just copy paste the .c and .h files in the folder where my .cpp file is present. Do I need to do something more ?
Update:
I found that the the file GraphUtils.c has the following code:
// OpenCV
#include <cv.h>
#include <cxcore.h>
#ifdef USE_HIGHGUI
#include <highgui.h>
#endif
I found that the cv.h, cxcore.h and highgui.h are actually present in opencv 2.3.1/opencv folder and so I changed it like this:
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#ifdef USE_HIGHGUI
#include <opencv/highgui.h>
#endif
Unfortunately this gave rise to more linking errors.
Update
The following program works fine.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include<conio.h>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
Mat img = imread("xyz.bmp", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
getch();
return 0;
}
But this program always gives error; no header file recognized. so no function would work:
#include "cv.h" //main OpenCV header
#include "highgui.h" //GUI header
int main() {
// declare a new IplImage pointer
IplImage* myimage;
// load an image
myimage = cvLoadImage("sayyidsmile.jpg",1); //change the file name with your own image
//create a new window & display the image
cvNamedWindow("Smile", 1);
cvMoveWindow("Smile", 100, 100);
cvShowImage("Smile", myimage);
//wait for key to close the window
cvWaitKey(0);
cvDestroyWindow( "Smile" );
cvReleaseImage( &myimage );
return 0;
}
Details on Env. Variables
I followed this article to set EVs.
Currently my variables are like this:
Name Value
OpenCV: C:\Users\Yuvue\Desktop\OpenCV2.3.1
INCLUDE: %OPENCV%\build\include
LIB: %OPENCV%\build\x86\vc10\lib
Path: %OPENCV%\build\x86\vc10\bin
Under Properties => VC++ Directories=> Library Directories, I have added the following:
$(OPENCV)\build\x86\vc10\lib
The second program compiles when I explicitly gives path of cv.h in the include. But if I do so with any of the third party libraries when they have used #include, it starts giving linking error (my original question).
Please help me sort this!!

ERROR: identifier "img" is undefined

I'm beginner to openCV. I dowloaded opencv2.4.5 and visual studio express 2012 then i followed this link http://opencv-srf.blogspot.in/2013/05/installing-configuring-opencv-with-vs.html for setup everything in environment variable etc. Then i followed below link http://opencv-srf.blogspot.in/2013/06/load-display-image.html to create sample application. I included proper #include path. But i'm getting error.
#include "stdafx.h"
#include <C:\opencv\build\include\opencv\cv.h>
#include <C:\opencv\build\include\opencv\cxcore.h>
#include <C:\opencv\build\include\opencv\highgui.h>
#include "C:\opencv\build\include\opencv2\highgui\highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
please do not use an absolute path for the includes, this is totally non-portable.
it should look like this:
// the usual suspects:
#include "opencv2\core\core.hpp" // Mat is defined here.
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\highgui\highgui.hpp"
also, to make this work, your "additional include folders" should point to "opencv/build/include"
and avoid the old c-api headers, like cv.h, highgui.h, cxcore.h