Using Qt to configure OpenCV library failed - c++

I'm new to Qt creator. Yesterday, I followed the official instructions to configure OpenCV library but it failed. I tried everything on the Internet but it just didn't work. Detailed are listed as belows:
test code is simple, I only want to ensure whether the library works:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello World!" << endl;
return 0;
}
My project configuration is like below :
I thought there might be a problem in debugger. I configure the debugger and I'm quite sure it's ok. The picture is here:
But it just doesn't work. When I click build and run, it says:
C1083: cannot open containing files: "opencv2/opencv.hpp": No such
file or directory.
What's strange is when I include <files> in the editor, the automatic code completion can detect the existence of the OpenCV library and hint after <opencv2/> that there are opencv.hpp, core.hpp .etc. and in the Include Hierarchy, the opencv.hpp exists.
So what might be the problem?

Related

libclang not finding headers in <> brackets on Mac with Xcode

Edit:
This program compiles. It's only when run does it fail to find iostream. I'm using the libclang.dylib that is bundled with Xcode.
I've written a small tool to begin working with libclang. I'm trying to parse TranslationUnits. The following program is saved in the file tool.cpp. Once compiled and run, it tries to parse tool.cpp as a TU. It's failing to get a clean run with default headers as it cannot find iostream on my Mac. After several attempts to supply arguments that point to the file, it still doesn't work. Any ideas?
#include "tool.h"
#include <iostream>
int main(int argc, char* argv[]) {
CXIndex index = clang_createIndex(0,0);
const char *args[] = {
"-I/usr/include",
"-I/usr/local/include",
"-I.",
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
//Should be here
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
}
;
Output:
tool.cpp 6:10: 'iostream' file not found
I've got the same issue. I am trying to add CPP to iOS Objective-C. It's not working. I found that this is about next "pain" from Apple because they do not use standard C++ library anymore. I've tried everything that mentioned on this site but haven't found any solution:

CImg Compilation Error: t_normal not in global namespace

I'm currently working on a class assignment that requires the use of the CImg library. To be clear, the assignment is not linking the library into the program; The class is using it access the pixel data for later use in the heart of the assignment.
I'm working in Xcode (OS X 10.10). CImg (2.2.2) is installed from homebrew, and I've managed to navigate the weird way Xcode deals with search paths (added the header to the section), and have successfully-ish included CImg.
my full code is as below.
#include <iostream>
#define cimg_display 0 //I don't need X11 at all
#include "CImg.h"
using namespace cimg_library;
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
However, I get 17 Compile-time errors from CImg.h, which are very unusual, and all of the form:
"No member named 't_normal' in the global namespace; did you mean simply 't_normal'?"
Thinking I might have received a bad download, I have attempted to redownload CImg, with no luck. I have also gotten to this same point with non-homebrew versions of CImg.
To verify the download, I also compiled the examples from the command line and they ran perfectly.
Is there a problem with CImg that I'm not aware of, a problem with Xcode that I'm not aware of, or is there something fundamental that I'm missing (definitely an option, my C-style programming is a little rusty) ?
halp pls.
Your code runs fine if you do this:
Create a new Xcode project, with:
type = "Command Line Tool"
language = "C++"
Then go to "Build Settings" and add the path to the directory containing CImg.h to your "User Header Search Paths"

Struggling with dlib, linker errors and save_jpeg in XCode

First, I am new to C++ and dlib but I have successfully built the examples and started working on my own project. Things have been progressing smoothly until I try to save a jpeg. Attempting to compile code using dlib::save_jpeg throws a linker error and I cannot track down the solution. I have attempted to add #define DLIB_JPEG_SUPPORT above and below my #includes but no luck. I am using XCode and used cmake -G "Xcode" .. when I compiled the examples. Relevant code below. Since I am on a Mac, I have added header and library search paths for X11 (for dlib gui), OpenCV, and DLIB. I have libjpeg.dylib and linked that to my project with and without #define DLIB_JPEG_SUPPORT in main.cpp. Is there some other build setting I need to specify? Thank you in advance for your help.
Finally, I have seen other questions and pages about dlib and libjpeg issues but no luck yet. And yes I have source.cpp included in the project.
// the standard stuff
#include <string>
#include <iostream>
#include <unistd.h>
// opencv mat object
#include <opencv2/opencv.hpp>
// dlib>
#include <dlib/opencv.h>
#include <dlib/image_io.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_transforms.h>
int main(int argc, const char * argv[]) {
// retrieving images from a TCP connection
// decode data stream
img = cv::imdecode(rawImage, CV_LOAD_IMAGE_COLOR);
// perform image processing
dlib::cv_image<dlib::bgr_pixel> d_image(img);
// finally save the result to jpg
std::string fname = argv[1] + std::to_string(image_id) + ".jpg";
dlib::save_jpeg(d_image, fname); // <- line that won't compile
return 0;
}
After quit a bit of struggling and side-by-side comparisons I finally found the issue. In XCode go to to Build Settings and modify Other Linker Flags, Run Search Paths, and Other C++ Flags to match the compiled and working face_ex example. I wholesale copied all of those flags and included a missing libjpeg.dylib and was able to get things running. It should look something like this for the C++ flags . Hope this helps the next person.

Getting CImg to work in XCode

Im attempting to get CImg (1.6.8) to work in XCode (7.2) running OSX 10.11.2
#include <iostream>
#include "CImg.h"
int main(int argc, const char * argv[])
{
std::cout << "Hello, World!\n";
return 0;
}
ERRORS:
Use of undeclared identifier 'LC_COLLATE_MASK'
Unknown type name 'locale_t'; did you mean 'locale'?
Long list of errors all concerning unkown type names , undeclared identifiers and too many arguments given follows.
ERRORS
For simplicity CImg.h and X11 are in the project folder and is an explicit search path but I have various unsolved dependencies:
Is there a general method for adding pretty much any library to integrate in Xcode ?
How and where would these dependencies be resolved?
Additional Info :
The Project settings for include dirs are recursive for the X11 folder.
Have tried it with 32bit and 64bit configs.
Firstly, you need to tell Xcode where your header files are - specifically CImg.h.
To do that, first click the area marked red, then the green then the blue and in the Header Search Paths field, enter the directory that contains the file CImg.h.
Normally you then have to set up the Library Search Paths immediately below, and the libraries to link to. But as CImg is a header-only library, there is no need in this specific case.
Finally, I inserted one line of code to avoid all the X11 stuff since OSX no longer ships with X11 and your code doesn't do any X11 stuff anyway.
#include <iostream>
#define cimg_display 0
#include "CImg.h"
int main(int argc, const char * argv[])
{
std::cout << "Hello, World!\n";
return 0;
}
It now runs fine - as you can see at the foot of the screen capture.
Hope that helps.

How to run a simple cpp file that requires QT?

I have QT 5.1.1 installed on my machine, but I'm having some troubles using it. I'm trying to run the following simple program that requires QT:
//Playing Video
#include "cv.h"
#include "opencv2\objdetect\objdetect.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\features2d\features2d.hpp"
#include "opencv2\calib3d\calib3d.hpp"
#include "opencv2\nonfree\nonfree.hpp"
#include "highgui.h"
#include <openbr\openbr_plugin.h>
using namespace cv;
static void printTemplate(const br::Template &t)
{
const QPoint firstEye = t.file.get<QPoint>("Affine_0");
const QPoint secondEye = t.file.get<QPoint>("Affine_1");
printf("%s eyes: (%d, %d) (%d, %d)\n", qPrintable(t.file.fileName()), firstEye.x(), firstEye.y(), secondEye.x(), secondEye.y());
}
int main(int argc, char *argv[])
{
br::Context::initialize(argc, argv);
// Retrieve classes for enrolling and comparing templates using the FaceRecognition algorithm
QSharedPointer<br::Transform> transform = br::Transform::fromAlgorithm("FaceRecognition");
QSharedPointer<br::Distance> distance = br::Distance::fromAlgorithm("FaceRecognition");
// Initialize templates
br::Template queryA("../data/MEDS/img/S354-01-t10_01.jpg");
br::Template queryB("../data/MEDS/img/S382-08-t10_01.jpg");
br::Template target("../data/MEDS/img/S354-02-t10_01.jpg");
// Enroll templates
queryA >> *transform;
queryB >> *transform;
target >> *transform;
printTemplate(queryA);
printTemplate(queryB);
printTemplate(target);
// Compare templates
float comparisonA = distance->compare(target, queryA);
float comparisonB = distance->compare(target, queryB);
// Scores range from 0 to 1 and represent match probability
printf("Genuine match score: %.3f\n", comparisonA);
printf("Impostor match score: %.3f\n", comparisonB);
br::Context::finalize();
return 0;
}
It also requires OpenCV 2.4.6.1 and OpenBR, but that's not the problem.
All the definitions (variables and functions) in the above code that are related to QT are undefined. I've tried to find the relevant h files in QT folder and to include them, but that did not succeed since I couldn't fine qtcore.h (but a different file named qtcore with lot's of includes that I don't now how to use). I've tried to add QT "include" directory under "additional include directories" in the project properties but that didn't work either. I've also tried to add QT "lib" folder under "additional library directories" but that also did not work.
Basically, I tried everything I could think of. Can someone please explain how to I use those QT definitions? I'm really stuck and I could use any help given.
Thanks,
Gil.
(Optional) Update to Qt 5.2.
Start Qt Creator.
Create a new Qt Widgets Application project. You can give the class/files random names, it doesn't matter. Uncheck the "generate form" option, as you don't need any forms.
Remove all the files other than main.cpp from the project. You do this by right-clicking on them in the project tree on the left and choosing Remove File.
Copy-paste your code into main cpp. Make sure you completely replace main.cpp's contents, the default contents shouldn't be there anymore.
Add the opencv library to the project. Right-click on the project's root, select "Add Library", and go from there.
Re-run qmake by right-clicking on the project root and selecting "Run qmake".
Build and run the project by pressing Ctrl-R (Cmd-R on mac).
Qt uses a (non-standard) custom toolchain that has to run before the Qt-dependent code can be compiled. I've never tried using Qt outside of QtCreator, but if you really need Qt I'd suggest you use the QtCreator IDE; if you're not using it already of course. It's a very decent IDE, even for non-Qt projects.
Also, if you haven't done so already, make sure the Qt SDK is installed; the headers alone are not enough. QtCreator by itself is also not enough, you'll need the SDK. If you don't feel like doing so, my suggestion would be to look at Poco. It's not a 1:1 replacement for Qt, but a very mature framework nevertheless.