Relative versus Absolute path to cv::imread OpenCV - xcode

I've got a cross platform error with OpenCV 2.3.1 and 2.4 on both VS2010 and Xcode 4.2
If I use cv::imread while giving the path to the image as an absolute path, it works. It does not work if that is a relative path. I usually put the images in the same dir as the code as well as all other dirs in the project just to be careful.
Much appreciated if anyone can answer this. Thank you!
Harish.

In Visual Studio, when you create a C++ project, it sets the project's working directory to the project dir, not the output dir of the executable.
That means that if you run the project from inside Visual Studio (by using the F5 button or the "Start Debugging" button), the program that you are writing won't be able to see the files that are in the same dir as the .exe file. But when you run the program from Windows Explorer (by double-clicking it) it will work as expected.
To fix this, you need to go in the Project properties window under Configuration properties -> Debugging, and change the Working Directory from $(ProjectDir) to $(OutputPath). You should change this both for the Debug and the Release configuration.
I don't know if this is the same case in XCode, but you can try this solution there too.

Related

How to publish my C# project using OpenCV Nuget packages in Visual Studio?

I have developed an opencv application using windows form and C#.
The opencv packages I got from the Nuget packages manager (EMGU.CV and ZedGraph).
Everything works fine in visual studio, but when I publish the project and install the program in my machine, it throws an exception when I click a button that performs some opencv operations.
I guess the opencv packages didn't come along with the final published project, so how do I do to make it export when publishing, I thought it would be an automated process, I have already used other nuget packages and I had no problem with it.
What Am I missing here?
After some days waiting for an answer, and looking for solutions, I've figured it out how to solve this issue.
I came across this question:The type initializer for 'Emgu.CV.CvInvoke' threw an exception
Which led me to this: http://www.emgu.com/wiki/index.php/Download_And_Installation#The_type_initializer_for_.27Emgu.CV.CvInvoke.27_threw_an_exception.
More precisely this part:
First of all, I don't know why the compilation runs fine inside visual studio enviroment and why not when publishing the project as it is. For some reason, the Nuget packges are not enough for publishing the project, you need to add the .dll files manually yourself (not sure why this occurs once I have worked with Nuget packages before and this workaround was not necessary).
To find the .dll files you go to your project directory, then you go to bin\Debug\x64 or bin\Debug\x86 (depends on which operating system you are targetting - 32 bits or 64 bits -in my case I added all .dll files from x86 folder, I guess you can add from both folders if in doubt).
The Debug folder of your project is build every time you run the project inside Visual Studio enviroment, so if your Debug folder is empty then you just need to run the project one time to be able to find the auto generated files inside that folder. Just a side note here, you can use either the Debug or the Release folder inside bin, just remember to check if you compiled the project in Debug mode for Debug folder, or Release mode for Release folder, otherwise the desired folder will be empty, as explained before, I found no differences between the files generated, I added the dll files from Debug\x86.
Once you have located the .dll files, you go to Visual Studio, right click on the project in the Solution Explorer tab, then Add ---> Existing Item.
Go to the folder where the .dll files are, select all and click Add.
Once you have done this, the .dll file will be shown in the Solution Explorer.
Right click on each .dll file added in the Solution Explorer, and open the properties tab by clicking Properties. On the Properties tab, go to option Copy to Directory and change the field to Copy Always (the emgu documentation link provided above states to use the option "Copy if newer", but to make sure I chose "Copy always", it worked fine for me). Repeat the process for all .dll files added.
Now you are ready to go for publishing the project as it is,just remember doing this every time before publishing your project to see if no .dll files are missing, so once you got to final version of your program, run it, and then make sure to check the .dll files, it might have new ones to add or to remove.

Visual Studio relative paths

I have some videofiles in our SVN repository alongside the sourcecode of my application. After checking out, the visual studio project is built using cmake.
my code needs to load the video files and it works well when running the application out of visual studio - but when the exe file in the release/debug folder is doubleclicked, it crashes because the relative paths are not right anymore. aparently when running it from within visual studio, the folder where the .sln file lies is considered the root of relative paths.
how can I refere to the videofiles from the code, such that the application works if i run it within visual studio as well as if i double click the exe in the release/bin folders, without to duplicate the videos? (they are quite big)
I need to do this because I have to hand in my application such that it can be compiled and run out of the box as well as executed without visual studio.
You can change your project's settings to make the IDE's behaviour match double-clicking on the executable, and then fix your relative paths.
For VS10/VS11, in the project's properties page, at the top select All Configurations from the Configuration: list.
Then select Configuration Properties->Debugging and set the Working Directory to $(OutDir)
Beware that running the executable from the command prompt in a directory other than $(OutDir) will still fail.

How do I Set an Executable's Search Path?

I'm not using the default Visual Studio project path to build my program into, because I want to emulate a release, and write tools to search for resources. After tinkering with the settings, I've got VS to output to the right folder, and to copy the DLLs to a bin folder in the main folder. However, I can't get the .EXE it generates to find the DLLs, it will only find what's in it's directory, but I don't want to be messy like that. The debugger works fine, but it won't work standalone. How do I tell VS to tell the .EXE where to find it's DLLs? Do I have to edit the PATH? That seems messy, as I've never had good experiences with it. I've tried Project Settings -> VC++ Directories, but it still won't find it, as I'm assuming that that's for .LIB files.
Here is a diagram of my folder hierarchy.
-root
--bin
---[Required DLLs]
--data
---[Program Resources (images, sounds, configs, etc.)]
--Program.exe
Using Visual C++ 2010 Express Edition.
How do I tell VS to tell the .EXE where to find it's DLLs?
Edit the Release Run Configuration and change the working directory where your dlls reside.
You will still have to run your exe through the ide for this to work.
Do I have to edit the PATH?
No
This doesn't have anything to do with Visual Studio. It is Windows that can't find the DLL. It has no reason to look in an arbitrary subdirectory for a DLL. It isn't otherwise clear whether these are implicitly loaded DLLs or if you use LoadLibrary to load them yourself.
You don't have much of a problem if you use LoadLibrary(), just pass the full path name of the DLL. GetModuleFileName(NULL, ...) helps you build the path string. You'll have a Big Problem if these are implicitly loaded. In that case, there should be preciously few reasons to not store the DLLs in the same directory as the EXE. And yes, you don't want to mess with the PATH environment variable. Or the current working directory.

VS2010 error : LNK1181 : cannot open input file xxxx.obj (only in debug mode)

I am using visual Studio 2010, trying to build a big solution having many VC++ projects converted from older Visual Studio builds.
The problem is, it gives me this LNK1181 for the 'root' project of the solution (the project on which all other projects are dependent) but only in DEBUG mode (win32). In release mode, it does not give me this error.
I noticed that this obj file is actually not created at all when in debug mode. Though the compiler doesn't give any error when it is building that cpp file.
What could be the problem? Is it related to those property manager sheets too somehow or something else?
The project is downloaded from our Source Control System directly, and works fine on other machines so there is something wrong on mine :(.
Click on solution.
goto Build menu and clean the solution and again build the solution hopefully this action sove your issue
You probably solved this a long time ago, but when I had this exact issue, removing the source files used to create the object from the project and then re-adding them as existing items fixed the issue. Of course, this doesn't change the fact that you're using project/solution files from your repo that other people are using without issue, which is odd.
For what it's worth, I had accidentally added *.obj files to the project, and so it was throwing this error.

Visual Studio project is placing object files in unrelated project directory. help

I have a visual studio solution that contains a project that builds a joystick handling library. Unfortunately, the output .lib file is placed in an unrelated folder on the drive. It is placed in another project. I noticed that $(TargetDir) is expanding to the unrelated project's path and not the current solutions path. How do I change this? I searched the visual studio project files for any matching path text and nothing turns up so I can't see how it is pointing to the wrong directory.
Ok, I screwed up. The project was pointing to the wrong directory (obviously) :-)

Resources