ImageMagick ++ Read Error ErrorMissingDelegate - c++

I have downloaded and installed ImageMagick++ from http://www.imagemagick.org/Magick++/.
I am using Windows7 32 bit and Visual Studio 2008. I want to use the ImageMagick in an existing project. I made the required/suggested changes to my project properties like adding dependencies etc. I added three libraries in the additional dependencies (CORE_RL_Magick++_.lib,CORE_RL_MagickCore_.lib and CORE_RL_MagickWand_.lib
I added
<Magick++.h> header file and
using namespace Magick
Then
Magick:: Image image (No error)
image.read("5.png") throws an error "ErrorMissingDelegate at memorry location ....".
I tried other image formats also, but same error.
Please help.

Related

using CImg in cpp

i'm trying to open image file for an university project using the CImg library.
when trying to load a png file, i get a message that the format file is not supported.
after some reading, i tried to install ImageMagick++ and add it as a dependency to my Visual Studio project following this post: http://www.imagemagick.org/discourse-server/viewtopic.php?t=30295
but it still doesn't work.
how do i add magick++ to my project? (even without the CImg library) is fine.

Cannot load any image with CImg

Any time I try to load an image I get an error saying CImg<unsigned char>::load(): Failed to recognize format of file. This happens for both jpg and png files.
I have found other posts about this saying to define cimg_use_png and cimg_use_jpeg, but then I get compilation errorstelling me I need png.n and jpeglib.h. Not sure where I'm supposed to get these from.
I'm not sure where I've gone wrong, so I don't know what to ask specifically. What's gone wrong?
If you want to open JPEG images, you need to install libjpeg and compile and link against it.
If you want to open PNG images, you need to install libpng and libz (for the compression) and compile and link against them.
At the moment, you should be able to use NetPBM format images - i.e. PBM, PGM and PPM.
Well, after two painful days of trying to work out how on Earth Visual Studio 2017 works, and how to install and integrate libjpeg with it, I can now explain how to install CImg and libjpeg on Windows.
Step 1
You need to have Visual Studio 2017 installed, which means you need Windows 7 with SP1 or better. When installing it, be sure to include "Windows 8.1 SDK"
Step 2
Download libjpeg from the IJG website. I took jpegsr9b.zip as it is the latest.
Step 3
Unzip the file and store it in a directory called libjpeg in your HOME directory.
Step 4
Go to Start>All Programs>Microsoft Visual Studio 2017>Visual Studio Tools > Developer Command Prompt for VS2017
Navigate to the directory you just unzipped. That will be something like this:
cd libjpeg
cd jpeg-9b
Step 5
Now you are going to need to find a file called win32.mak. I found mine in C:\Program Files\Microsoft SDKs\Windows\v7.0\Include. Yours may be somewhere else if you have Windows 8.1 SDK. Anyway, wherever it is, you need to add its containing directory to your includes. So I did:
set INCLUDE=%INCLUDE%;C:\Program Files\Microsoft SDKs\Windows\v7.0\Include
Step 6
Now run nmake to get your SLN - some weird Microsoft "solution" file. The command is:
nmake -f makefile.vc setup-v10
And you should get a file called jpeg.sln - hurray!
Step 7
Now start Visual Studio 2017, and open the jpeg.sln file you just created and build the project. It will create a Release directory in your libjpeg directory and inside the Release directory you will find jpeg.lib. You have now installed libjpeg.
Step 8
Close that project, and start a new C++ command-line project and write your CImg-based program. I wrote the simplest ever:
#define cimg_use_jpeg
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> img("C:\\Users\\Mark\\test.jpg");
img.display("Image");
return 0;
}
Step 9
Download CImg.h from Github, and save it in a directory called CImg in your HOME directory.
Step 10
Now tell Visual Studio where the include files (for CImg and libjpeg) are and where the library files (for libjpeg) are:
Step 11
Now tell Visual Studio 2017 that you want to link with libjpeg:
Step 12
Now you can compile, link and run your CImg program and load JPEG files and display them on the screen!
If you are using cmake on Linux/macOS, this answer shows you the way.
If you are compiling on macOS from the command line, you'll need to have XQuartz installed if you are display images on the screen, and you'll want something like this:
g++ -std=c++11 sample.cpp -o sample -I /opt/X11/include -L /opt/X11/lib -lX11 -ljpeg -lpng -lz
If you want CImg to work with jpeg or png images, you need to supply appropriate library.
Here's a tutorial how to install libjpeg to Visual Studio project. It's basically a 2019 update to Mark Setchell's answer.
How to install libjpeg to your project
Download jpegsr9c.zip (or newer) zip with source code
Extract the archive to a folder.
Copy the address of the folder extracted from archive
Search for Developer Command Prompt in Start menu
Navigate to extracted folder in Developer Command Prompt:
cd "C:\Users\HP\Downloads\temp\jpeg-9c"
Use right click to paste.
Run this command:
NMAKE /f makefile.vs setup-v15
Open jpeg.sln (which was now created).
In Solution Explorer, right click on the project. Select Retarget projects. Confirm prompt.
If you want to build your project for 64-bit platform: Right click on solution, select Configuration Manager and add new platform x64
Build solution
Now let's move to your project with CImg. Create a folder jpeglib in your project (it's IncludedLibraries\jpeglib for me). And add it to Project Properties -> C/C++ -> Additional Include Directories and to Project Properties -> Linker -> Additional Library Directories
Add jpeg.lib to Project Properties -> Linker -> Input -> Additional Dependencies
Copy x64/Release/jpeg.lib to this folder.
Search for all header files (`.h) in jpeg project and copy them to this folder.
Add #define cimg_use_jpeg before #include "CImg.h" in your project
All done! CImg is now able to read and save jpeg files.

OpenCV w/ CUDA build fail on Visual Studio 2013 [duplicate]

I'm trying to build OpenCV 2.4.6 on Windows 8 in Visual Studio 2012. Having downloaded the source from https://github.com/Itseez/opencv I generate (leaving the default configuration) using cmake and then load the resulting file ALL_BUILD.vcxproj into Visual Studio 2012. I then try to build it. Several of the modules do indeed build (e.g. core, flann, imgproc, ...) but I am trying to build highgui so that I can use the PDB file for debugging my code (which fails to open a video file). The build errors start with this and many similar errors:
error C2039: 'max' : is not a member of 'std' C:\OpenCV2.4.6\3rdparty\openexr\Imath\ImathMatrixAlgo.cpp 1094 1 IlmImf
One fix for errors like this (e.g. in this answer) is to add #include <algorithm> to the failing files. I tried that on a few files and it seems to work but I'm nervous about locally changing the source for a popular library. It must build on Windows (you can download the binaries, though not the PDB files, from the OpenCV sourceforge site) so I would like to understand how to build it on my machine without changing the source.
Am I missing something out in the configuration step? Is there some path setting etc. missing on my machine? Why am I getting these errors and how should I fix them?
========== EDIT ==========
Looking at the directory path this appears to be a problem with one of the 3rd party dependencies, OpenEXR. Looking on Github it appears to be version 1.7.1 of OpenEXR that is used in OpenCV 2.4.6. The instructions in the OpenCV's Quick Start Installation on Windows state:
In case of the Eigen library it is again a case of download and extract to the D:/OpenCV/dep directory.
Same as above with OpenEXR.
so I downloaded the OpenEXR 1.7.1 source code release and extracted the resulting files putting the directory openexr-1.7.1 into C:\OpenCV2.4.6\dep.
Then I ran cmake and tried to build the resulting Visual Studio solution. Sadly I see the same errors.
I was stumbling on the same issue while compiling OpenEXR. Then I found the solution googling for openexr std::min.
There is an issue opened on OpenCV where it says that, when using VS2013 Preview, you must add the line #include <algorithm> in the file where you're using std::min and std::max.
I put that line into the files where these methods are called and voilĂ ! Compilation succeeded.
You probably need to #define NOMINMAX. Try putting it before any other includes.
If that helps, then put in the you project's preprocessor defines.
There's lots of info about this, just search for NOMINMAX. Here's one post about it.
#include <iostream>
#include <algorithm>
Just include above 2 lines to the cpp file and the compilation error will disappear.

OpenCV installation Problems with Visual Studio 2013

I have installed OpenCV 2.4.8 with Visual Studio 2013 using instruction found all over the Internet. I modified the property sheets and everything, but I am still facing a problem with the installation. When I try to run a test program, it gives me the following error:
Cannot open source file opencv2/core/core.hpp
Cannot open source file opencv2/highgui/highgui_c.h
Why does this error occur? I have followed all installation steps faithfully.
Although, I should point out one more thing: There weren't any instructions for VS 2013, but only for VS 2012, so I just modified it where it was necessary, like replacing vc11 with vc12.
Make sure that you have openCV directory in your project's include directory. You should add openCV's include directory not include\opencv2.
Can you give me your project's include inputs?
I think this is not opencv installation issue. Make sure the include opencv path is correct in your solution.
You need to add correct header include paths and library paths in the red marked area for your project. Also after including that try to open the header files(opencv header files) from the solution using right mouse click "Open Document "something.h" " to make sure your included path is correct.

Visual Studio not using additional include directories for KinectBridgeWithOpenCVBasics D2D C++ Sample, but does for other solutions.

I'm working on adding some openCV features to a couple projects that use the Kinect and openGL/freeGLUT. I have downloaded and installed OpenCV using the pre-built libraries and successfully run a simple sample. Now I want to work with the Kinect Bridge with OpenCV Basics sample from the Kinect for Windows Developer Toolkit to get a better idea of how to use OpenCV with the Kinect. I downloaded the sample into my projects folder, opened the solution in visual studio and built it. I got the following errors:
Error 1 error C1083: Cannot open include file:
'opencv2/core/core.hpp': No such file or
directory c:\users\justin\documents\visual studio
2010\projects\kinectbridgewithopencvbasics-d2d\OpenCVHelper.h 17
and
Error 2 error C1083: Cannot open include file:
'opencv2/core/core.hpp': No such file or
directory c:\users\justin\documents\visual studio
2010\projects\kinectbridgewithopencvbasics-d2d\OpenCVFrameHelper.h 13
Initially I thought these errors were due to forgetting to specify the additional include directories. I added the same property sheet that my other OpenCV projects use to this one, but the errors remained. I tired copying the header files into the project folder: same thing. It seems like the only thing that works is specifying the full absolute file paths in the #include statements. I want to avoid doing this because visual studio wants me to change every #include in every file used in the project, including the openCV header files. I also tried shortening the name of my project folder in case the file path was too long (though I'm pretty sure that's more of an issue for the header file paths), but again no change.
The include directories and #includes that I'm trying to use are the same as in my other projects. I'm using Visual Studio 2010 on Windows 7 x64 based system.
Why would the additional include directory work for other projects, but not this one?
Usually when I see something like this it turns out to be a bad character in one of the prior include paths or other options that's messing everything up after it. I would take a look at your the command line page in the project configuration and see if you can spot anything amiss.