樹莓派——opencv篇

1、查看python3的版本

如果是python3.5的,請使用這個教程;如果是python3.7的,請使用這個教程

2、錯誤集合

遇到了以下的情況,請參考https://blog.csdn.net/u011736771/article/details/85960300或者https://blog.csdn.net/ninwji/article/details/100798014中的相關內容

爲什麼會遇到這種情況:

據我觀察,應該是在cmake的過程中,會發現連接不上服務器下載資源失敗的情況,根據這篇博文所說的,是cmake不支持https所引起的,我也覺得可能是需要翻牆才能下載資源所以纔會下載不成功。

[ 79%] Built target pch_Generate_opencv_xfeatures2d
[ 79%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o
/home/pi/my_opencv/opencv_contrib-3.4.0/modules/xfeatures2d/src/boostdesc.cpp:646:20: fatal error: boostdesc_bgm.i: No such file or directory
           #include "boostdesc_bgm.i"
                    ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/build.make:81: modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:16850: modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

這個錯誤的重點是這一句話:file not recognized:file truncated.

 這種情況按照https://blog.csdn.net/tonkeytong/article/details/52672782所說的,是因爲在編譯過程中發生異常退出情況導致數據丟失,看到這句話我明白了,在十一點整,宿舍斷電,樹莓派突然停電導致我的編譯突然中斷,出現了這個問題,我太難了,然後make clean之後重新編譯。

[ 90%] Linking CXX executable ../../bin/example_bgsegm_bgfg
/usr/bin/ld: ../../lib/libopencv_bgsegm.so.3.4.0: file not recognized: file truncated
collect2: error: ld returned 1 exit status
make[2]: *** [modules/bgsegm/CMakeFiles/example_bgsegm_bgfg.dir/build.make:94: bin/example_bgsegm_bgfg] Error 1
make[1]: *** [CMakeFiles/Makefile2:19360: modules/bgsegm/CMakeFiles/example_bgsegm_bgfg.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

這個問題我沒有找到相關的答案,我的python版本是3.7,我原先一開始安裝的opencv版本是3.4,我認爲可能是python和opencv之間版本不匹配所造成的問題吧,後來我安裝得opencv版本是4.1就可以成功安裝了

     {"inpaint", (PyCFunction)pyopencv_cv_xphoto_inpaint, METH_VARARGS | METH_KEYWORDS, "inpaint(src, mask, dst, algorithmType) -> None\n.   @brief The function implements different single-image inpainting algorithms.\n.   \n.   See the original paper @cite He2012 for details.\n.   \n.   @param src source image, it could be of any type and any number of channels from 1 to 4. In case of\n.   3- and 4-channels images the function expect them in CIELab colorspace or similar one, where first\n.   color component shows intensity, while second and third shows colors. Nonetheless you can try any\n.   colorspaces.\n.   @param mask mask (CV_8UC1), where non-zero pixels indicate valid image area, while zero pixels\n.   indicate area to be inpainted\n.   @param dst destination image\n.   @param algorithmType see xphoto::InpaintTypes"},
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:63: modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:21769: modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

在opencv4.1 make到100%的時候,樹莓派出現死機的情況,強制斷電重新make之後也會出現這個問題,判斷是交換空間不足的原因,根據這篇博文,解決了我的問題。

樹莓派換源的問題,一定要看清楚你樹莓派的版本,不能隨便換源,要搞清楚你是buster還是strech,例如:

deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi

是不一樣的,新手尤其要注意這個問題,不然你更新軟件的時候容易出現各種各樣的問題。

總結:我在樹莓派上弄這個opencv花了五天的時間,其中遇到了各種各樣的問題,我覺得是我一開始的方向就沒對導致出現了好多問題,所以希望我的博文可以幫助到你,喜歡的話可以點贊、收藏、分享,這對我幫助很大,謝謝!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章