How to get the ImageMagick library working with Swift 4/iOS 11? - ios

I'm trying to get ImageMagick to work in my iOS project. Unfortunately everything I have tried so far has not worked.
Cocoapods
The most obvious approach would be to use the cocoapod. Unfortunately after installing the cocoapod there doesn't appear to be anything exposed to swift to import. Maybe I'm missing something obvious and if anyone has any ideas that would be great. Unfortunately the documentation is lacking as far as specific examples go.
Static library - approach #1
The official ImageMagick docs provide some instructions to compile the latest version of ImageMagick and include a static library in your Xcode project. Unfortunately the first step of the instructions requires running a bash script imagemagick_compile.sh which I cannot find. Once again I could be missing something obvious.
Static library - approach #2
After some additional searching I found the ~Claudio guy which the ImageMagick docs mention as the maintainer of the iOS version of ImageMagick. He has a repo with similar instructions as provided by ImageMagick but this repo includes a bash script to compile and generate a static library of ImageMagick. I tried running the script directly ./all.sh 6.8.8-9 but soon realized I hadn't setup a build directory they way his instructions outlined and I got stuck getting libpng installed correctly.
Static library - approach #3
The same repo with the instructions to compile and generate a static library also includes an old sample iOS project with a static library already included for an older version of ImageMagick. This just about worked except the ImageMagick library has a class Timer that clashes with the Timer class provided by Swift4/iOS so I couldn't get my project to compile using this static library of ImageMagick.
ImageMagick iOS Questions on SO
There are a handful of other questions on Stack Overflow that deal with running ImageMagick on iOS so I know other people have done it but nothing very recent. If anyone has any ideas that would be greatly appreciated, thanks!
Un-answered question on how to use ImageMagick on iOS: ImageMagick iOS image Potentially useful comment that includes some of the same links that I provided above.
Someone already using ImageMagick for iOS but gives no details on how it was implemented: ImageMagick circular dstortion on iOS
Un-answered question from someone already using ImageMagick in their app: Ios - ImageMagick - No Image Created after Distortion
More recent question related to warnings using the cocoapod version: iOS: ImageMagick compiler warnings in Xcode
Other questions: https://stackoverflow.com/search?q=imagemagick+ios Unfortunately I haven't found any of these that have helped.

To integrate ImageMagick into iOS you will need to do the following:
Install the library available here https://www.imagemagick.org/download/iOS/
You will need a Swift-Objective-C bridging header that includes:
#import "ImageMagick.h"
#import "MagickWand.h"
You will need to modify any functions that reference Timer to Foundation.Timer, this will resolve any conflicts with the ImageMagick library
You will need to add under Your target > Build Phases > Link Binary With Libraries > "libxml2.tbd".
Hope this helps

Related

Finding boost framework with Cmake for iOS

I have Boost built as a framework for iOS. This is currently installed in Applications/Xcode.app/Contents/Developer/Library/Frameworks/.
When I create a "hand-generated" XCode project, I have no problems using this framework.
I'm now trying to use CMake to generate an XCode project. I found this helpful, cross-compiling toolchain (https://github.com/cristeab/ios-cmake). This works as long as I do not include
find_package( Boost )
But when the above line is added to my CMakeLists.txt file, I get a "Boost_INCLUDE_DIR-NOTFOUND"
So question is: has anyone had success in using CMake with Boost for iOS? If so, any help on how to go about it is greatly appreciated.
I found another SO user trying to do something similar here: How to find a iOS/mac OS X framework via Cmake
But it does not offer much details other than using "CMAKE_FRAMEWORK_PATH".
So any help is much appreciated.
Thanks...
find_package cannot find boost built for ios (tested on cmake 3.13 and 3.14)
Was able to solve it in following way.
Build boost using https://github.com/faithfracture/Apple-Boost-BuildScript
set BOOST_ROOT to Apple-Boost-BuildScript/src/boost_x_xx_x
for iOS:
set(Boost_INCLUDE_DIRS "${BOOST_ROOT}")
set(Boost_LIBRARIES "${BOOST_ROOT}/iphone-build/stage/lib/libboost_date_time.a")
set(Boost_LIBRARIES "${Boost_LIBRARIES};${BOOST_ROOT}/iphone-build/stage/lib/libboost_regex.a")
set(Boost_LIBRARIES "${Boost_LIBRARIES};${BOOST_ROOT}/iphone-build/stage/lib/libboost_system.a")
iOS simulator:
set(Boost_INCLUDE_DIRS "${BOOST_ROOT}")
set(Boost_LIBRARIES "${BOOST_ROOT}/iphonesim-build/stage/lib/libboost_date_time.a")
set(Boost_LIBRARIES "${Boost_LIBRARIES};${BOOST_ROOT}/iphonesim-build/stage/lib/libboost_regex.a")
set(Boost_LIBRARIES "${Boost_LIBRARIES};${BOOST_ROOT}/iphonesim-build/stage/lib/libboost_system.a")
I hope it's not too late:)
I came across almost same issue, find_package always complain that can not find the lib, even the search path is correct, notice that the similar issue also exist for Android NDK
For the ios I suggest:
Enable boost debug by set(Boost_DEBUG ON), then check the path specified is correct or not, ref to this link for more info
How can I get CMake to find my alternative Boost installation?
Try find_host_package instead of find_package, I found some clue in ios.cmake which may lead to the issue:
# only search the iOS sdks, not the remainder of the host filesystem
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Tesseract integration to my Project on xCode 6.3 iOS 8.3

I'm really digging the web and stackoverflow questions but none of them does not solve my problem.
I'm trying use Tesseract OCR in my iOS Project, but integration did not go what I expected. I follow the instructions in this blog and I did the all things but still I m not able to integrate it. May be because of the new updates, anyway I just want to solve my problem.
So I have added all files to my project about tesseract and leptonica and I have added tessdata to my project.
I also tried the run existing project on github but still the problem exists.
Error is
I checked eng.cube.lm file exists in project and I also linked it.
Please help!
I could not found my answer, but I found another way to do it. I used cocoapods to get OCR library . This is the simplest way to adding dependency to your project.
This very clear how to use cocoapods quick guide,
This is the pod that I used tesseract OCR pod
This is the installation guide to tesseract OCR
If you follow the tips, everything will be good.
On the other hand, I think my problem was file broken or out of date to new versions. My first way was very dirty and rough. To use tesseract on iOS , best way is the Cocoapods
I hope this will help someone!

Linking Header File with Main.Cpp file in Codeblocks

I am trying to use codeblocks to compile the code available here
The thing is every time I try to build and run, I run into the following error:
|/.../head_pose_estimation/opencv2/core/core.hpp|48|fatal error: opencv2/core.hpp: No such file or directory
Does anyone know how I can fix this? Thank you!
You do not have the pre-built (compiled) version of OpenCV, what you currently have are the source files. If you want to do something special with OpenCV (Target/GPU SUpport etc) then you will need to build the framework using an appropriate guide.
If however you simply want to use OpenCV in the most common way then download the pre-built libraries from the OpenCV.org website.
NOTE:
If you are using OpenCV with MinGW compiler, I do not remember if the pre-built is actually pre-built for MinGW. (I dont think they do) In this case you will HAVE to built the libraries. You can find a guide here

cannot setup Opencv 2.4.6 , opencv_core231d.lib Not Found Error

Hello everyone;
i had opencv 2.2 on my vs2010, and i wanted to update so i went to opencv site and:
i've downloaded OpenCV for Windows (ver 2.4.6)
i've extracted it to c:\opencv2.4
i've set the Environment Variable as doc said here: http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#windowssetpathandenviromentvariable
( i didnt know what is "PATH EDITOR" so i've just changed Environment variables)
i made property sprite sheets as opencv doc said here: http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to
5.but Doc Was Old, and there was no "include" folder in OpenCV2.4/opencv/build/x64/vc10 so I did set include Directory to OpenCV2.4/opencv/build/include in My property sprite sheet.
everything seems true and VS detect include libraries But
VS2010 throw following error when i want to Build the solution:
1>LINK : fatal error LNK1104: cannot open file 'opencv_core231d.lib'
Strange thing is there is no "opencv_core231d.lib" File in c:\opencv2.4 at all!!!
:(
what is the problem?
This is a Linker error, so make sure you are trying to link the correct libraries.
I would suggest to use CMake, which definitely simplifies configuring projects, specially those having dependencies like OpenCV (you can take a look to the OpenCV documentation, or any blog explaining the steps: http://marcosnietoblog.wordpress.com/2011/11/19/opencv-for-windows-easy-installation-using-cmake/ )
By the way, I use to have several versions of opencv on the same folder:
C:\OpenCV\opencv2.4.3
C:\OpenCV\opencv2.4.6
...
So I can easily switch within CMake setting the OpenCV_DIR.
opencv_core231d.lib is a debug version, all the *d.lib and *d.dll files in openCV are with debug symbols.
It is likely that the pre-built release you downloaded doesn't contain debug ones.
either download te source and build both debug and release. Or, if you don't care how opencv works internally, just change the linker flags to use the same lib names with the d
edit. or of course if you donwloaded opencv 2.4.6 the file would be opencv_core246d.lib

OpenCV 2.4.4 and Tesseract 3.02.02 Don't link together

I'm using iOS 6.1 and XCode 4.6
I have a problem, OpenCV needs to be compiled with libc++ (LLVM C++ 11), while Tesseract 3.02.03 needs to be compiled with "default compiler".
How can I overcome this problem. at this point I can compile and link only If I comment out OpenCV code or comment out OCR code. cannot make them both work together.
Any ideas??
I am by no means an expert with C++ but I had the same problem and by some trial and error and lots of internet searching I think I managed to solve it.
As I understand it, the problem is that opencv and tesseract are built with different standard libraries. The latest opencv is built with libc++ while tesseract is built with stdlibc++
The solution is to rebuild one of them so they both use the same standard library. I decided to recompile tesseract and followed the instructions found here which references a build script that is used to build the library.
I modified this script (again, by trial an error, not really sure this is the best way) to used the clang++ compiler (CXX="/usr/bin/clang++") and use libc++ (CXXFLAGS="$CFLAGS -stdlib=libc++") and it compiles (albiet with some warnings). You may also need to copy some headers as the script doesn't seem to copy them all.
Then just use this library instead of the downloaded one in your iOS project (remember to change back to libc++ in build settings) and everything will compile and link just fine.
So far it seems to work properly in runtime.

Resources