树莓派——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花了五天的时间,其中遇到了各种各样的问题,我觉得是我一开始的方向就没对导致出现了好多问题,所以希望我的博文可以帮助到你,喜欢的话可以点赞、收藏、分享,这对我帮助很大,谢谢!

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