如何链接Fred的Magick脚本TextCleaner与XCode项目?

时间:2021-07-03 08:59:23

I decided to rephrase the question. Here is the problem:

我决定重新表述这个问题。这是问题:

I've managed to run textcleaner.exe within my c++ program by calling: system("/usr/local/bin/textcleaner g -e normalize -f 25 -o 10 [path to infile] [path to outfile]");

我已经运行了textcleaner。在我的c++程序中调用:系统(“/usr/local/bin/textcleaner g -e normalize - f25 -o 10[路径到infile][路径到outfile]”);

But now I get the error:

但是现在我得到了一个错误:

/usr/local/bin/textcleaner: line 389: convert: command not found

/usr/local/bin/textcleaner:第389行:转换:命令未找到。

/usr/local/bin/textcleaner: line 400: [: : integer expression expected

/usr/local/bin/textcleaner:第400行::期望的整数表达式。

/usr/local/bin/textcleaner: line 403: convert: command not found

第403行:convert:命令未找到

/usr/local/bin/textcleaner: line 417: [: : integer expression expected

/usr/local/bin/textcleaner:第417行:[::期望的整数表达式。

/usr/local/bin/textcleaner: line 423: [: : integer expression expected

/usr/local/bin/textcleaner:第423行:[::期望的整数表达式。

/usr/local/bin/textcleaner: line 429: convert: command not found

第429行:convert:命令未找到

--- FILE /Users/~/Desktop/kimlik/kimlik1.bmp NOT READABLE OR HAS ZERO SIZE ---

- - - - - -文件/用户/ ~ /桌面/ kimlik / kimlik1。bmp不可读或零大小---

So what is the problem here? I am giving a correct image with the right path, so I think instead of the last line, the problem lies with the convert command within textcleaner.exe. How can I call textcleaner.exe and convert.exe at the same time so that when running the textcleaner.exe, it knows what command convert is?

那么这里的问题是什么呢?我用正确的路径给出了正确的图像,所以我认为问题不在于最后一行,而是在于textcleaner.exe中的convert命令。我怎么能叫textcleaner ?exe和转换。同时执行exe,以便在运行textcleaner时执行。exe,它知道什么是命令转换?

1 个解决方案

#1


1  

I wouldn't recommend calling an external script from a C++ application. You'll need to worry about paths, loading shell environments, and external error handling. Not really hard to do, but I feel unnecessary. I would argue that if your developing a C++ solution, than integrate with Magick++ directly. Try the following...

我不建议从c++应用程序调用外部脚本。您需要考虑路径、加载shell环境和外部错误处理。做起来并不难,但我觉得没有必要。我认为如果你开发一个c++解决方案,比直接与Magick++集成要好。试试下面的……

Ensure that you installed ImageMagick with Magick++ support. This is usually enabled by default.

确保使用Magick++支持安装了ImageMagick。这通常是默认启用的。

Update Xcode's Build Settings to include Magick++ flags.

更新Xcode的构建设置,包括Magick++ flags。

  • Run Magick++-config --cxxflags in your terminal. The return values should be copied under "Other C++ Flags" option.
  • 在终端运行Magick++-config -cxxflags。返回值应该在“其他c++标志”选项下复制。
  • Run Magick++-config --libs in your terminal. The return values should be copied under "Other Linker Flags" option.
  • 运行Magick++-config——在您的终端上运行libs。返回值应该在“其他链接器标志”选项下复制。

Xcode project should now support Magick++ library.

Xcode项目现在应该支持Magick++库。

Finally, evaluate the source of Fred's fantastic textcleaner script. You should be able to mimic his techniques directly in C++.

最后,评估Fred出色的textcleaner脚本的来源。您应该能够直接在c++中模仿他的技术。

For example. The script may generate the following convert command.

为例。脚本可以生成以下转换命令。

 convert \( $infile -colorspace gray -type grayscale -contrast-stretch 0 \) \
         \( -clone 0 -colorspace gray -negate -lat ${filtersize}x${filtersize}+${offset}% -contrast-stretch 0 \) \
         -compose copy_opacity -composite -fill "$bgcolor" -opaque none  \
         -sharpen 0x1 \ $outfile

Which can be implemented with something like...

可以用如下方法实现

#include <Magick++.h>

using namespace Magick;

int main(int argc, const char * argv[]) {
    long
        filtersize = 15,
        offest = 5;
    const char
        * bgcolor = "white",
        * infile  = "wizard:",
        * outfile = "output.png";

    InitializeMagick(argv[0]);
    Image alphaImage(infile);
    alphaImage.colorSpaceType(GRAYColorspace);
    alphaImage.type(GrayscaleType);
    alphaImage.contrastStretch(0, QuantumRange);
    Image betaImage(alphaImage);
    betaImage.negate();
    betaImage.adaptiveThreshold(filtersize, filtersize, offest);
    betaImage.contrastStretch(0, QuantumRange);
    alphaImage.composite(betaImage, 0, 0, CopyAlphaCompositeOp);
    alphaImage.fillColor(Color(bgcolor));
    alphaImage.opaque(Color("none"), Color(bgcolor));
    alphaImage.sharpen();
    alphaImage.write(outfile);
    return 0;
}

如何链接Fred的Magick脚本TextCleaner与XCode项目?

#1


1  

I wouldn't recommend calling an external script from a C++ application. You'll need to worry about paths, loading shell environments, and external error handling. Not really hard to do, but I feel unnecessary. I would argue that if your developing a C++ solution, than integrate with Magick++ directly. Try the following...

我不建议从c++应用程序调用外部脚本。您需要考虑路径、加载shell环境和外部错误处理。做起来并不难,但我觉得没有必要。我认为如果你开发一个c++解决方案,比直接与Magick++集成要好。试试下面的……

Ensure that you installed ImageMagick with Magick++ support. This is usually enabled by default.

确保使用Magick++支持安装了ImageMagick。这通常是默认启用的。

Update Xcode's Build Settings to include Magick++ flags.

更新Xcode的构建设置,包括Magick++ flags。

  • Run Magick++-config --cxxflags in your terminal. The return values should be copied under "Other C++ Flags" option.
  • 在终端运行Magick++-config -cxxflags。返回值应该在“其他c++标志”选项下复制。
  • Run Magick++-config --libs in your terminal. The return values should be copied under "Other Linker Flags" option.
  • 运行Magick++-config——在您的终端上运行libs。返回值应该在“其他链接器标志”选项下复制。

Xcode project should now support Magick++ library.

Xcode项目现在应该支持Magick++库。

Finally, evaluate the source of Fred's fantastic textcleaner script. You should be able to mimic his techniques directly in C++.

最后,评估Fred出色的textcleaner脚本的来源。您应该能够直接在c++中模仿他的技术。

For example. The script may generate the following convert command.

为例。脚本可以生成以下转换命令。

 convert \( $infile -colorspace gray -type grayscale -contrast-stretch 0 \) \
         \( -clone 0 -colorspace gray -negate -lat ${filtersize}x${filtersize}+${offset}% -contrast-stretch 0 \) \
         -compose copy_opacity -composite -fill "$bgcolor" -opaque none  \
         -sharpen 0x1 \ $outfile

Which can be implemented with something like...

可以用如下方法实现

#include <Magick++.h>

using namespace Magick;

int main(int argc, const char * argv[]) {
    long
        filtersize = 15,
        offest = 5;
    const char
        * bgcolor = "white",
        * infile  = "wizard:",
        * outfile = "output.png";

    InitializeMagick(argv[0]);
    Image alphaImage(infile);
    alphaImage.colorSpaceType(GRAYColorspace);
    alphaImage.type(GrayscaleType);
    alphaImage.contrastStretch(0, QuantumRange);
    Image betaImage(alphaImage);
    betaImage.negate();
    betaImage.adaptiveThreshold(filtersize, filtersize, offest);
    betaImage.contrastStretch(0, QuantumRange);
    alphaImage.composite(betaImage, 0, 0, CopyAlphaCompositeOp);
    alphaImage.fillColor(Color(bgcolor));
    alphaImage.opaque(Color("none"), Color(bgcolor));
    alphaImage.sharpen();
    alphaImage.write(outfile);
    return 0;
}

如何链接Fred的Magick脚本TextCleaner与XCode项目?