Linking OpenCV 2.4.2 with Visual Studio 2010 - visual-studio-2010

I have installed OpenCV as described here: Installing openCV 2.4 for C/C++ for Visual Studio.
I try to link openCV libraries and I am stuck at "the local method" in this tutorial.
I have two places with openCV files:
[username]/opencv (official)/ where I extracted openCV source (referred further as source directory)
[username]/opencv-build/ where I built openCV using cmake and then compiled it with Visual Studio (referred further as build directory)
The tutorial I try to follow says to link $(OPENCV_DIR)\include which refers to build directory. However, "include" folder in my build directory contains only some cmake files, while "include" in the source directory contains openCV headers (in folders opencv and opencv). I understand that I should rather use the source directory instead, but I tried with both and none of them works.
Next, the tutorial says to link $(OPENCV_DIR)\libs. I have a folder "lib" so I guess it is just a spelling error. My folder "lib" contains two folders: "Debug" and "Release". Should I add [username]/opencv-build/lib/Debug to Debug Property Page and [username]/opencv-build/lib/Release to Release Property Page?
I have added 242 version libraries to Linker input in both Property Pages.
Whatever I did, Visual Studio highlights all of the include statements and hence, everything else.
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
Any ideas what I am doing wrong?
EDIT after go4sri answer:
Change to opencv\include\opencv solved the problems with includes (except "stdafx.h"), however I tried the following "hello world" now:
#include <cv.h>
#include <highgui.h>
int main ( int argc, char **argv )
{
cvNamedWindow( "My Window", 1 );
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
CvFont font;
double hScale = 1.0;
double vScale = 1.0;
int lineWidth = 1;
cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
hScale, vScale, 0, lineWidth );
cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return 0;
}
Although, includes are no longer highlighted, everything else still is. Errors are "identifier XXX is undefined".
EDIT
I have copied some of the files from the previous versions of openCV to <source_directory>\include\opencv2. Now Visual Studio does not highlight anything, however when I try to build it, I get "unresolved external symbol" error for: _cvCreateImage, _cvInitFont, _cvNamedWindow, _cvPutText, _cvShowImage and _cvWaitKey.

You were right to use the include from the source directory.
Change the includes to :
#include <opencv\cv.h>
#include <opencv\cxcore.h>
#include <opencv\highgui.h>
They are all contained in the opencv directory under include.This is the standard way of using Opencv.
However, you can also change the include options to <source_dir>\include\opencv;<source_dir>\include\opencv2;<source_dir>\include [This is not recommended]
For the libs:
Yes. Use the Debug directory in the additional library directories option for Debug( and Release for the release)
You will also need to change the input library names - Note that all debug libraries end with a d while the release libs do not.
For example:
The debug lib will be named: opencv_imgproc242d.lib
The release lib will be named: opencv_imgproc242.lib
Hope this helps...

Related

where is the interface header file of HIDL in AOSP?

I studied the HIDL using Nfc code in AOSP .
As i know, when INfc.hal is compiled, INfc.h is autogenerated like following picture.
In NxpService.cpp, there is code like following
#include <android/hardware/nfc/1.1/INfc.h>
But, I couldn't find that path.
where is the real path of android/hardware/nfc/1.1/INfc.h?
In addition, I became curious how gcc compile works in NxpService.cpp that uses INfc.h.
Could you explain how gcc compiler can find INfc.h and work without compile error?
INfc.hal
Path: /hardware/interfaces/nfc/1.1/INfc.hal
Android.bp
hidl_interface {
name: "android.hardware.nfc#1.1",
root: "android.hardware",
NxpService.cpp
Path: /hardware/nxp/nfc/1.1/NxpService.cpp
#include <android/hardware/nfc/1.1/INfc.h>
...
int main(){
sp<INfc> nfc_service = new Nfc();
status_t status = nfc_service->registerAsService();
android.hardware.nfc#1.1 would be at hardware/interfaces/nfc/1.1/ here.
The mappings for Android provided interfaces to their actual location are shown here https://source.android.com/devices/architecture/hidl/interfaces.
The files you look for are all auto-generated by hidl-gen, and they usually locate in out directory, e.g.
$ANDROID_ROOT/out/soong/.intermediates/hardware/interfaces/nfc/1.1/android.hardware.nfc#1.1_genc++_headers/gen/android/hardware/nfc/1.1

CMAKE for windows DLL with OpenCV project

Behold: My Cmakelists.txt file
project(facedetectlib)
cmake_minimum_required(VERSION 2.8)
include (GenerateExportHeader)
SET(CMAKE_VERBOSE_MAKEFILE TRUE)
file(GLOB HEADER_LIST ./include/*.h)
include_directories(./include)
aux_source_directory(. SRC_LIST)
find_package(OpenCV REQUIRED )
# Allow the developer to select if Dynamic or Static libraries are built
OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
# Set the LIB_TYPE variable to STATIC
SET (LIB_TYPE STATIC)
IF (BUILD_SHARED_LIBS)
# User wants to build Dynamic Libraries, so change the LIB_TYPE variable to CMake keyword 'SHARED'
SET (LIB_TYPE SHARED)
ENDIF (BUILD_SHARED_LIBS)
add_library(ocvfacedetectlib ${LIB_TYPE} ${SRC_LIST} ${HEADER_LIST})
target_link_libraries(ocvfacedetectlib ${OpenCV_LIBS})
GENERATE_EXPORT_HEADER( ocvfacedetectlib
BASE_NAME ocvfacedetectlib
EXPORT_MACRO_NAME ocvfacedetectlib_EXPORT
EXPORT_FILE_NAME ocvfacedetectlib_Export.h
STATIC_DEFINE ocvfacedetectlib_BUILT_AS_STATIC
)
Using this cmake file and piecing together some instructions from here:
http://www.cmake.org/Wiki/BuildingWinDLL
I am trying to figure out if the DLL is getting built correctly. My header file for my little library has the following in it:
#include "ocvfacedetectlib_Export.h"
typedef unsigned char uint8_t;
extern "C" {
ocvfacedetectlib_EXPORT uint8_t * facedetect( uint8_t *imageData, long buffsize, unsigned char *retbuffer );
}
And then I have in my .cpp file this:
ocvfacedetectlib_EXPORT uint8_t * facedetect( uint8_t *imageData, long buffsize, unsigned char *retbuffer )
{ ..do stuff using OpenCV
...}
This seems to be enough to generate a DLL but I am not sure if it is being built correctly - I am unable to load it use js.ctypes() which is what I am trying to do as my end goal.
For what it's worth—my .cpp has a main() method as well and when I build the code to an .exe it runs.
What is the proper way to generate a windows DLL from a CMake project for later versions of CMake than 2.8, and what has to be changed in the source code to make it work?

Open CV, image loading issue on Mac OS X

I think my question is pretty basic. I was trying to get Open CV to install on my OSX Lion. I had followed all the steps recommended on this link http://tilomitra.com/opencv-on-mac-osx/
However, when I run the C++ code recommended on the website in Xcode, it fails to load an image with the cvLoadImage( ) function. I have placed my image in the project folder (as recommended). Here is the code I was running:
// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.hpp>
int main(int argc, char** argv)
{
IplImage * pInpImg = 0;
// Load an image from file - change this based on your image name
pInpImg = cvLoadImage("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!pInpImg)
{
fprintf(stderr, "failed to load input image\n");
return -1;
}
// Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if( !cvSaveImage("my_image_copy.png", pInpImg) )
{
fprintf(stderr, "failed to write image file\n");
}
// Remember to free image memory after using it!
cvReleaseImage(&pInpImg);
return 0;
}
So during execution, the code builds successfully, but always ends up in the following loop and halts execution:
if(!pInpImg)
{
fprintf(stderr, "failed to load input image\n");
return -1;
}
Has anyone faced such a problem before? How could I solve this?
(During installation of 'Macports' and 'Cmake', I had received an alert saying that Xcode was not installed or was installed without 'Command Line Tools'. But as per another thread on this forum, I had installed these from the Xcode-->Preferences-->Downloads folder on installing Xcode.
However, still during installation, 'Macports' and 'Cmake' gave me warnings, but installed anyway. But could this be the issue? )
Thank you!
The problem is that you're putting the image into the project folder instead of the folder containing your executable. You can either put the image file in the folder with the executable or put the full path to the image in the call to cvLoadImage.
Older versions of Xcode put the executable in either the build/Debug or build/Release folder in the project folder. Newer versions of Xcode put the build products in the project folder in the DerivedData folder. You can find the DerivedData folder by going to File -> Project Settings… and clicking the arrow next to the folder path:
In the project folders, go to 'Products' > right click on the executable file > 'Show in Finder' > put the input image there. The output image ('.png' file) will go here as well.

Where is the "App Bundle" looking for my media folder? Folder found when running app from Qt Creator, "file not found" when using Terminal

I'm having a little trouble making my app bundle work from the terminal or just double clicking it.
This App actually compiles, links and runs perfectly within the Qt Creator IDE. But, if I try to open it from the terminal I get a "media/file.x file not found" error. The App bundle nor the /Contents/MacOS/executable is finding the "media" folder that is supposed to be beside the executable.
In my app I do something like:
openFile("media/file.x");
In Windows and Linux, this file WILL be found if the "media" folder is exactly in the same hierarchical position of the executable (beside it). On the Mac I have discovered it works differently cause Qt Creator builds an "App Bundle" and the actual executable is inside the /Contents/MacOS folder, so I copied the "media" manually there. This worked without any hassle when "playing" my app from the Qt Creator but as mentioned before it doesn't work when running the bundle itself.
So does anyone know where or how can I homogenize the look for this "media" folder so it works on both: Qt Creator and the App bundle?
Lately, I have been using the following command to "install" the folder on the bundle.
mac {
MediaFiles.files = media
MediaFiles.path = Contents/MacOS
QMAKE_BUNDLE_DATA += MediaFiles
}
Thanks for your help.
After looking for a few days I found a couple of posts discussing the relative path problem. I was just not searching with the right words... The answer is displayed in:
Relative Paths Not Working in Xcode C++
http://www.experimentgarden.com/2009/06/how-to-load-resource-from-your.html
Basically it is necessary to add this:
//On the include part
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif
// On the main of your app
// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
// error!
}
CFRelease(resourcesURL);
chdir(path);
std::cout << "Current Path: " << path << std::endl;
#endif
// ----------------------------------------------------------------------------
IMPORTANT:
The chdir, changes the working path of the app, so it is not necessary to change you relative code after that...

C++ includes problem with NetBeans 7.0 under MacOS X using sshfs

That's what we have
1) MacOS X Lion, NetBeans 7.0
2) C++ project with source files located on sshfs mounted volume (using Fuse4X)
3) Some libraries header files alse located on sshfs mounted volume.
When I open some source file Code Assistance displays a lot of errors "Couldn't resolve an include" near all lines with include directive and file path containing uppercase characters
#include "SomeModule.h" // error here
#include <Lib/Header.h> // also error here
#include <otherlib/file.h> // wow, no errors
Of course directories containing these headers are added to include path and if I hold 'cmd' button and hover any of these includes correct include path is displayed, but NetBeans still says he couldn't locate that file.
Besides if I create 2 files: File.h и file.h on sshfs volume and try to include them
#include <sshfs/file.h> // includes file.h
#include <sshfs/File.h> // displays an error
My question is what should I do for NetBeans could see, parse and provide content assistance in projects located on sshfs volume?

Resources