META-DREAMER/Qwik-e-Classifier

Compile PipeCNN Alexnet openCV demo for DE10-Nano

nocduro opened this issue · 2 comments

Need to get cross compiler working with opencv

https://docs.opencv.org/2.4/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.html

# done on ubuntu 16.04 24 vCPU instance
sudo apt install cmake libv4l-dev libopencv-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev x264 v4l-utils ffmpeg
cd ~
git clone https://github.com/opencv/opencv.git
cd opencv
git tag
# checkout the latest 2.4 release
# https://github.com/opencv/opencv/releases
git checkout -b 2.4.13.6 tags/2.4.13.6
mkdir build
cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_V4L=ON -D-DENABLE_NEON=ON -DCMAKE_TOOLCHAIN_FILE=~/opencv/platforms/linux/arm-gnueabi.toolchain.cmake ~/opencv
make -j24

This builds opencv on the server, but now I'm not sure what to do... Link the main.cpp to this?

EDIT: I might not have built with enough flags. Here are the flags in the Makefile for PipeCNN:

#add your cross compile OpenCV PATH here
OCV_INCLUDES = -I/usr/local/opencv-arm/include/
OCV_LIBDIRS = -L/usr/local/opencv-arm/lib 
OCV_LIBS =  -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_imgcodecs -lopencv_videoio

EDIT2:
Found the folders, now just need to enable the required opencv plugins (or are they called extensions?)

$ ls ~/opencv/build/lib
libopencv_calib3d_pch_dephelp.a     libopencv_highgui.so.2.4              libopencv_perf_core_pch_dephelp.a        libopencv_test_features2d_pch_dephelp.a
libopencv_calib3d.so                libopencv_highgui.so.2.4.13           libopencv_perf_features2d_pch_dephelp.a  libopencv_test_flann_pch_dephelp.a
libopencv_calib3d.so.2.4            libopencv_imgproc_pch_dephelp.a       libopencv_perf_gpu_pch_dephelp.a         libopencv_test_gpu_pch_dephelp.a
libopencv_calib3d.so.2.4.13         libopencv_imgproc.so                  libopencv_perf_highgui_pch_dephelp.a     libopencv_test_highgui_pch_dephelp.a
libopencv_contrib_pch_dephelp.a     libopencv_imgproc.so.2.4              libopencv_perf_imgproc_pch_dephelp.a     libopencv_test_imgproc_pch_dephelp.a
libopencv_contrib.so                libopencv_imgproc.so.2.4.13           libopencv_perf_nonfree_pch_dephelp.a     libopencv_test_legacy_pch_dephelp.a
libopencv_contrib.so.2.4            libopencv_legacy_pch_dephelp.a        libopencv_perf_objdetect_pch_dephelp.a   libopencv_test_ml_pch_dephelp.a
libopencv_contrib.so.2.4.13         libopencv_legacy.so                   libopencv_perf_ocl_pch_dephelp.a         libopencv_test_nonfree_pch_dephelp.a
libopencv_core_pch_dephelp.a        libopencv_legacy.so.2.4               libopencv_perf_photo_pch_dephelp.a       libopencv_test_objdetect_pch_dephelp.a
libopencv_core.so                   libopencv_legacy.so.2.4.13            libopencv_perf_stitching_pch_dephelp.a   libopencv_test_ocl_pch_dephelp.a
libopencv_core.so.2.4               libopencv_ml_pch_dephelp.a            libopencv_perf_superres_pch_dephelp.a    libopencv_test_photo_pch_dephelp.a
libopencv_core.so.2.4.13            libopencv_ml.so                       libopencv_perf_video_pch_dephelp.a       libopencv_test_stitching_pch_dephelp.a
libopencv_features2d_pch_dephelp.a  libopencv_ml.so.2.4                   libopencv_photo_pch_dephelp.a            libopencv_test_superres_pch_dephelp.a
libopencv_features2d.so             libopencv_ml.so.2.4.13                libopencv_photo.so                       libopencv_test_video_pch_dephelp.a
libopencv_features2d.so.2.4         libopencv_nonfree_pch_dephelp.a       libopencv_photo.so.2.4                   libopencv_ts.a
libopencv_features2d.so.2.4.13      libopencv_nonfree.so                  libopencv_photo.so.2.4.13                libopencv_ts_pch_dephelp.a
libopencv_flann_pch_dephelp.a       libopencv_nonfree.so.2.4              libopencv_stitching_pch_dephelp.a        libopencv_video_pch_dephelp.a
libopencv_flann.so                  libopencv_nonfree.so.2.4.13           libopencv_stitching.so                   libopencv_video.so
libopencv_flann.so.2.4              libopencv_objdetect_pch_dephelp.a     libopencv_stitching.so.2.4               libopencv_video.so.2.4
libopencv_flann.so.2.4.13           libopencv_objdetect.so                libopencv_stitching.so.2.4.13            libopencv_video.so.2.4.13
libopencv_gpu_pch_dephelp.a         libopencv_objdetect.so.2.4            libopencv_superres_pch_dephelp.a         libopencv_videostab_pch_dephelp.a
libopencv_gpu.so                    libopencv_objdetect.so.2.4.13         libopencv_superres.so                    libopencv_videostab.so
libopencv_gpu.so.2.4                libopencv_ocl_pch_dephelp.a           libopencv_superres.so.2.4                libopencv_videostab.so.2.4
libopencv_gpu.so.2.4.13             libopencv_ocl.so                      libopencv_superres.so.2.4.13             libopencv_videostab.so.2.4.13
libopencv_haartraining_engine.a     libopencv_ocl.so.2.4                  libopencv_test_calib3d_pch_dephelp.a
libopencv_highgui_pch_dephelp.a     libopencv_ocl.so.2.4.13               libopencv_test_contrib_pch_dephelp.a
libopencv_highgui.so                libopencv_perf_calib3d_pch_dephelp.a  libopencv_test_core_pch_dephelp.a

missing: -lopencv_imgcodecs -lopencv_videoio

EDIT3: can't figure out how to get those ones.
Here's another useful command

cd ~/opencv/build
cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_V4L=ON -DWITH_FFMPEG=ON -D-DENABLE_NEON=ON -DCMAKE_TOOLCHAIN_FILE=~/opencv/platforms/linux/arm-gnueabi.toolchain.cmake ~/opencv
cmake --build . --target install

We can just compile on the FPGA board. The YOLO webcam + opencv + pipecnn is working! 671ms per inference right now