树莓派3B+运行arm_computer_library
參考:https://community.arm.com/graphics/b/blog/posts/cartoonifying-images-on-raspberry-pi-with-the-compute-library?CommentSortBy=CreatedDate&CommentSortOrder=Descending
根據官方博客進行測試ACL:Cartoonifying Images on Raspberry Pi with the Compute Library
我的情況是:我借助matlab實現與樹莓派的遠程連接,matlab的作用主要是傳輸文件用的和遠程連接。
1、我是在樹莓派上進行編譯的
官方代碼是:
# Install dependencies (g++, git and scons) sudo apt-get install g++ git scons # Clone Compute Library git clone https://github.com/Arm-software/ComputeLibrary.git # Enter ComputeLibrary folder cd ComputeLibrary # Build the library and the examples scons Werror=1 debug=0 asserts=0 neon=1 opencl=0 examples=1 build=native -j2?我是直接在電腦上載好的,然后傳給樹莓派,直接下太慢了
用:putFile(mypi,'C:/Users/NEVERGUVEIP/ComputeLibrary-#master.zip','/home/pi/')? 進行文件的傳輸,然后進行解壓
當我進行第一次編譯時,應該是沒有問題的,但是當我安裝第二個ACL庫,經行第二次編譯時,系統報錯,說是沒有target “-j2”.
(我直接運行scons,后面的一堆參數都沒用,我感覺只刪除‘-j2’應該就行了,因為直接scons的話,編譯時間太長了。還有這個-j2我現在都不知道啥意思。)
2、進行測試時
LD_LIBRARY_PATH=build/ ./build/examples/neon_convolution我從git上直接下載的ACL版本應該時最新版的吧,這時的neon_convolution不在build下,而是在examples文件夾下,這樣測試時就能通過了。直接運行官方代碼會報錯。說找不到文件。
3、運行實例時
我把他們的代碼直接復制到樹莓派,新建一個test.cpp文件. 然后用g++編譯。
home/pi/ComputeLibrary下面放的就是ACM的相關文件
一開始用g++ test.cpp,報錯,說找不到頭文件。
3.1 編譯報錯(1)?
arm_compute/runtime/NEON/NEFunctions.h:28:69: fatal error:?
arm_compute/runtime/NEON/functions/NEAbsoluteDifference.h:No such file or directory
?#include "arm_compute/runtime/NEON/functions/NEAbsoluteDifference.h"
解決方法:編譯時要添加路徑:就是-I后面的路徑,不然總是報錯,找不到頭文件。
g++ -I/home/pi/ComputeLibrary test.cpp3.2 編譯報錯(2)
/home/pi/ComputeLibrary/support/Half.h:36:25: fatal error: half/half.hpp: No such file or directory
?#include "half/half.hpp"
解決辦法:
這是因為half.cpp文件已經不在half文件下了,用sudo find -name? half.hpp可以發現這個文件在include文件夾下,所以修改
/home/pi/ComputeLibrary/support/Half.h文件中#include "half/half.hpp"為:#include "include/half/half.hpp"
3.3 繼續編譯報錯(3)
?utils/Utils.h:33:26: fatal error: libnpy/npy.hpp: No such file or directory
?#include "libnpy/npy.hpp"
這個和上個錯誤一樣,打開utils/Utils.h文件,修改為?#include "include/libnpy/npy.hpp"
3.4? 編譯繼續報錯
test.cpp:24:5: error: ‘PPMLoader’ was not declared in this scope
? ? ?PPMLoader ppm;
? ? ?^~~~~~~~~
test.cpp:25:5: error: ‘ppm’ was not declared in this scope
? ? ?ppm.open(argv[1]);
?
心里mmp呀,這TM還能讓人好好玩耍嗎。
解決辦法:PPMLoader是在:#include "utils/ImageLoader.h"頭文件下。把這個代碼加到頭文件中
3.5 還報錯,我已經到崩壞的邊緣了,別惹我
In file included from test.cpp:4:0:
utils/ImageLoader.h:36:27: fatal error: stb/stb_image.h: No such file or directory
?#include "stb/stb_image.h"
解決方法:和前倆個錯誤一樣,修改ImageLoader.h的文件的中“?#include "stb/stb_image.h"”,為?#include "include/stb/stb_image.h"
。。。。。。。。。。。。。。。。
3.6 理論上經過修改的代碼是沒有問題了,可是進行g++編譯時,還是報錯,這次的錯,呵呵,感覺解決不了,或者說這就不應該這樣編譯。因為我使用g++對系統自帶的源碼進行編譯時,報了同樣的錯。
/tmp/ccvZEwyw.o: In function `arm_compute::TensorInfo::~TensorInfo()':
neon_cartoon_effect.cpp:(.text._ZN11arm_compute10TensorInfoD2Ev[_ZN11arm_compute10TensorInfoD5Ev]+0x38): undefined reference to `vtable for arm_compute::TensorInfo'
collect2: error: ld returned 1 exit status
/
在解決bug的途中,直到我發現了真相
4、總結(真相)
4.1真相
其實這個例子是包含在ACL中的,在examples 下找到neon_cartoon_effect.cpp 。
在ACM18.11版本中的源碼為:這個源碼和官方博客中的代碼有不點區別了的。我們進行scons時,已經進行編譯過了的。
#include "arm_compute/runtime/NEON/NEFunctions.h"#include "arm_compute/core/Types.h" #include "utils/ImageLoader.h" #include "utils/Utils.h"using namespace arm_compute; using namespace utils;class NEONCartoonEffectExample : public Example { public:bool do_setup(int argc, char **argv) override{// Open PPM filePPMLoader ppm;if(argc < 2){// Print helpstd::cout << "Usage: ./build/neon_cartoon_effect [input_image.ppm]\n\n";std::cout << "No input_image provided, creating a dummy 640x480 image\n";// Create an empty grayscale 640x480 imagesrc_img.allocator()->init(TensorInfo(640, 480, Format::U8));}else{ppm.open(argv[1]);ppm.init_image(src_img, Format::U8);}// Initialize just the dimensions and format of the images:gaus5x5_img.allocator()->init(*src_img.info());canny_edge_img.allocator()->init(*src_img.info());dst_img.allocator()->init(*src_img.info());// Configure the functions to callgaus5x5.configure(&src_img, &gaus5x5_img, BorderMode::REPLICATE);canny_edge.configure(&src_img, &canny_edge_img, 100, 80, 3, 1, BorderMode::REPLICATE);sub.configure(&gaus5x5_img, &canny_edge_img, &dst_img, ConvertPolicy::SATURATE);// Now that the padding requirements are known we can allocate the images:src_img.allocator()->allocate();dst_img.allocator()->allocate();gaus5x5_img.allocator()->allocate();canny_edge_img.allocator()->allocate();// Fill the input image with the content of the PPM image if a filename was provided:if(ppm.is_open()){ppm.fill_image(src_img);output_filename = std::string(argv[1]) + "_out.ppm";}return true;}void do_run() override{// Execute the functions:gaus5x5.run();canny_edge.run();sub.run();}void do_teardown() override{// Save the result to file:if(!output_filename.empty()){save_to_ppm(dst_img, output_filename); // save_to_ppm maps and unmaps the image to store as PPM}}private:Image src_img{}, dst_img{}, gaus5x5_img{}, canny_edge_img{};NEGaussian5x5 gaus5x5{};NECannyEdge canny_edge{};NEArithmeticSubtraction sub{};std::string output_filename{}; };/** Main program for cartoon effect test** @param[in] argc Number of arguments* @param[in] argv Arguments ( [optional] Path to PPM image to process )*/ int main(int argc, char **argv) {return utils::run_example<NEONCartoonEffectExample>(argc, argv); }4.2 測試圖片
LD_LIBRARY_PATH=build/ ./build/examples/neon_cartoon_effect? school_bus.ppm
4.2 測試效果圖
?
左邊是原圖,右邊是效果圖。老子老吃飯去了/ 一個來自對c++不懂人的吶喊
總結
以上是生活随笔為你收集整理的树莓派3B+运行arm_computer_library的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux 文件的复制
- 下一篇: 树莓派编译深度模型