Compiling in OpenCV - opencv

Every time I try to compile this code in OpenCV, I keep getting this error. All I want to do is create a window:
//#include <iostream>
//#include <stdio.h>
#include "highgui.h"
int main() {
int cvNamedWindow(const char* name, int flags = CV_WINDOW_AUTOSIZE);
{
cvNamedWindow("sample");
}
cvDestroyWindow("sample");
}
However I'm getting this error:
window.cpp:4:21: fatal error: highgui.h: No such file or directory
I have checked in the necessary folder and highgui.h is very much installed.
Any help?

Include files as following
#include "opencv2/highgui/highgui.hpp"
And compile the file
g++ -ggdb `pkg-config --cflags opencv` filename `pkg-config --libs opencv`

If you have the OpenCV include as part of the include path, it should be
#include "opencv/highgui.h"
or
#include "opencv2/highgui/highgui.hpp"
depending on you using the c or c++

Related

How to create a simple makefile for an OpenCV project?

I'm working remotely on Linux operating system, where I'm trying to compile a .cu file.
The folder contains a main.cu file which does an histogram equalization. It uses opencv libraries.
How should I create the makefile? Everything I tried didn't work.
I got this error: undefined reference to cv::imread(cv::String const&, int)'
Is this the right way to make a makefile?
BINARY=cuda
SOURCES= main.cu
LIBPATHS = /usr/include/opencv2/libopencv_highgui.so
CC=nvcc
OBJECTS=$(SOURCES:.cu=.o)
INCFLAGS=$(foreach TMP,$(INCPATHS),-I$(TMP))
LIBFLAGS=$(foreach TMP,$(LIBPATHS),-L$(TMP))
OPENCV = `pkg-config opencv --cflags --libs`
LIBS = $(OPENCV)
$(PROG):$(SRCS)
$(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)
all:
$(CC) $(INCFLAGS) $(SOURCES) -o $(BINARY)
distclean:
rm -f $(BINARY)
clean:
rm -f $(BINARY)
I got these two include in my main.cu file:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
Thanks a lot

OpenCV linking error by using `cv::cvtColor`

I am getting this error:
usr/bin/ld: CMakeFiles/stereo_img.dir/stereo_img.cpp.o: undefined reference to symbol '_ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii'
//usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
In my CmakeLists.txt I added:
add_definitions(-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_nonfree -lopencv_objdetect -lopencv_features2d )
I am using these includes:
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
I can use other types from opencv, such as cv::Mat.

Using xmlXPathDistinct in xmllib

I don't understand how to use xmlXPathDistinct for xmllib2
// xmlNodeSetPtr xmlXPathDistinct (xmlNodeSetPtr nodes)
xmlXPathObjectPtr result;
...
if(result) {
xmlNodeSetPtr nodeset = xmlXPathDistinct(result->nodesetval);
--> warning: initialization makes pointer from integer without a cast
Could someone provide me an example?
Riccardo
edit:
gcc -o test2 test2.c -L/usr/local/lib xml2-config --cflags --libs -lpthread -m64
Linux mymachine 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Ok, found. All these headers must be included
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/valid.h>
#include <libxml/hash.h>
#include <libxml/xmlerror.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
#include <libxml/uri.h>
#include <libxml/xpointer.h>

Simple CPP file failed to compile with Clang

#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Parse/ParseAST.h"
#include "clang/Rewrite/Rewriter.h"
#include "clang/Rewrite/Rewriters.h"
#include "llvm/Support/Host.h"
int main()
{
return 0;
}
I am compiling it as
clang++ -I/home/pc/llvm-3.3.src/tools/clang/include -I/home/pc/llvm-3.3-build/tools/clang/include -I/usr/local/include -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-uninitialized -Wnon-virtual-dtor -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -c -o simple.o simple.cpp
I am getting error as 'clang/Rewrite/Rewriter.h' file not found
About a year ago (before the release of llvm 3.2), ClangRewrite was split into 2 libraries: ClangRewriteCore and ClangRewriteFrontend.
This means that:
clang/Rewrite/Rewriter.h is now clang/Rewrite/Core/Rewriter.h.
clang/Rewrite/Rewriters.h is now clang/Rewrite/Frontend/Rewriters.h.
libclangRewrite.a is now libclangRewriteCore.a and libclangRewriteFrontend.a.
You can see the change in the LLVM repository here.

How to compile youtube-api application

I am developing a custom Youtube video player. But I am not able to compile the program. I am missing something in Makefile. My program looks like
main.c
#include<gdata/services/youtube/gdata-youtube-service.h>
int main(int argc, char **argv[])
{
printf("Youtube Application\n");
return 0;
}
makefile
gcc `pkg-config --cflags --libs libgdata-google-1.2`  -lgdata-google-1.2 main.c -o youtube
When I compile, it is giving error like
error: gdata/services/youtube/gdata-youtube-service.h: No such file or directory
Do I got to install some other packages ? Or, i need to include something in my Makefile ?
Are you on Debian/Ubuntu? You probably want the libgdata-dev package.
$ apt-file search gdata/services/youtube/gdata-youtube-service.h
libgdata-dev: /usr/include/libgdata/gdata/services/youtube/gdata-youtube-service.h
Tried compiling it too, and tried using one of the methods declared in gdata-youtube-service.h
$ gcc `pkg-config --cflags --libs libgdata` main.c -o yt
$ ./yt
Youtube Application

Resources