thinker board 系统安装环境配置

本文介绍在ThinkBoard上安装配置OpenCV的过程,并提供Python及C++示例代码实现面部检测。同时涵盖CSI摄像头配置及故障排查方法,以及GStreamer和MJPG-streamer的应用。
Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

在入手think board前,用的是树莓派3B+

tinker board国内用的比较少,所以资料也比较少,如果用的话最好用谷歌浏览器进行搜索资料

系统安装步骤也同树莓派类同,请参考树莓派。

接下来配置环境:

OpenCV in python (Face Detection)

#Install
$ sudo apt-get update
$ sudo apt-get upgrade
#Install a few developer tools
$ sudo apt-get install -y build-essential git cmake pkg-config
#Install image I/O packages which allow us to load image file formats such as JPEG, PNG, TIFF, etc.
$ sudo apt-get install -y libjpeg-dev libtiff5-dev libpng-dev
#Install video I/O packages
$ sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
#Install the GTK development library
$ sudo apt-get install -y libgtk2.0-dev
#Various operations inside of OpenCV (such as matrix operations) can be optimized using added dependencies
$ sudo apt-get install -y libatlas-base-dev gfortran
#Install the Python 2.7 and Python 3 header files 
$ sudo apt-get install -y python2.7-dev python3-dev python-opencv


$ wget https://github.com/opencv/opencv/archive/3.3.0.zip
$ unzip 3.3.0.zip
$ cd opencv-3.3.0
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=Release -D WITH_LIBV4L=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ sudo make install

测试csi摄像头

$ gst-launch-1.0 v4l2src ! video/x-raw,format=NV12,width=640,height=480 ! videoconvert ! autovideosink
 输入这个命令后就能看到摄像头显示的图片。

TROUBLESHOOTING

If the Camera Module isn't working correctly, please use below command to check whether the Camera Module be detected by Tinker Board.
 

$ ls /dev/video*
 

You will see /dev/video0 /dev/video1 /dev/video2. If not, there are number of things to try:

  • Is the ribbon cable attached to the Camera Serial Interface (CSI), not the Display Serial Interface (DSI)? The ribbon connector will fit into either port. The Camera port is located near the HDMI connector.
  • Are the ribbon connectors all firmly seated, and are they the right way round? They must be straight in their sockets.
  • Is the Camera Module connector, between the smaller black Camera Module itself and the PCB, firmly attached? Sometimes this connection can come loose during transit or when putting the Camera Module in a case. Using a fingernail, flip up the connector on the PCB, then reconnect it with gentle pressure. It engages with a very slight click. Don't force it; if it doesn't engage, it's probably slightly misaligned.
  • Is your power supply sufficient? The adapter should be 5V/3A that is more stable for the use of the camera.

Gstreamer

#preview
$ gst-launch-1.0 v4l2src ! videoconvert ! autovideosink
$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=NV12,width=640,height=480 ! videoconvert ! autovideosink
 
#capture
$ gst-launch-1.0 v4l2src num-buffers=10 ! video/x-raw,format=NV12,width=640,height=480 ! jpegenc ! multifilesink location=image_%02d.jpg
$ gst-launch-1.0 v4l2src num-buffers=10 ! video/x-raw,format=NV12,width=640,height=480 ! jpegenc ! multifilesink location=image.jpg
 
#recording
$ gst-launch-1.0 v4l2src num-buffers=512 ! video/x-raw,format=NV12,width=640,height=480,framerate=30/1 ! queue ! mpph264enc ! queue ! h264parse ! mpegtsmux ! filesink location=/home/linaro/vga.ts
 
#show picture
$ gst-launch-1.0 playbin uri=file:///home//linaro//image.jpg
$ gst-launch-1.0 filesrc location=image.jpg ! decodebin ! imagefreeze ! autovideosink
 
#play video
$ gst-launch-1.0 playbin video-sink=rkximagesink uri=file:///home/linaro/vga.ts
$ gst-launch-1.0 uridecodebin uri=file:///home/linaro/vga.ts ! rkximagesink

MJPG-streamer

#Install
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install subversion libjpeg62-turbo-dev imagemagick
$ svn co https://svn.code.sf.net/p/mjpg-streamer/code/
$ cd code/mjpg-streamer
$ make
$ sudo make install

#Start MJPG-streamer
$ cd ~/code/mjpg-streamer
$ ./mjpg_streamer -i "./input_uvc.so -y" -o "./output_http.so -w ./www"

sample code in Python

import sys, os, cv2

print(cv2.__version__)
cv2.setNumThreads(4)

#please copy ~/opencv-3.3.0/data/harrcascades_cuda/haarcascade_frontalface_alt.xml to /home/linaro/
faceCascade = cv2.CascadeClassifier("/home/linaro/haarcascade_frontalface_alt.xml")
cap = cv2.VideoCapture("v4l2src ! video/x-raw,format=NV12,width=640,height=480 ! videoconvert ! appsink")

while cap.isOpened():
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
    cv2.imshow("Frame", frame)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

Sample code in c++ 
Sample code - test.c

#include <opencv2/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;


const String keys
    = "{ help           | false | print usage         }"
      "{ camera_width   | 640   | camera device width  }"
      "{ camera_height  | 480   | camera device height }"
;

int main(int argc, char** argv)
{
    CommandLineParser parser(argc, argv, keys);


    if (parser.get<bool>("help"))
    {
        parser.printMessage();
        return 0;
    }

    VideoCapture cap;

    cap = VideoCapture("v4l2src ! video/x-raw,format=NV12,width=640,height=480 ! videoconvert ! appsink");
    if(!cap.isOpened())
    {
        cout << "Couldn't find camera: " << cameraDevice << endl;
        return -1;
    }

    cap.set(CAP_PROP_FRAME_WIDTH, parser.get<int>("camera_width"));
    cap.set(CAP_PROP_FRAME_HEIGHT, parser.get<int>("camera_height"));

    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera/video or read image

        if (frame.empty())
        {
            waitKey();
            break;
        }

        imshow("image", frame);
        if (waitKey(1) >= 0) break;
    }

    return 0;
}

Build test.c

$ gcc test.c `pkg-config --cflags --libs opencv`

Gstreamer in C code
Sample code - test.c

#include <gst/gst.h>

int main(int argc, char *argv[]) {
    GstElement *pipeline;
    GstBus *bus;
    GstMessage *msg;
    
    /* Initialize GStreamer */
    gst_init (&argc, &argv);
    
    /* Build the pipeline */
    pipeline = gst_parse_launch ("v4l2src num-buffers=512 ! video/x-raw,format=NV12,width=640,height=480 ! videoconvert ! autovideosink", NULL);
    
    /* Start playing */
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    
    /* Wait until error or EOS */
    bus = gst_element_get_bus (pipeline);
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    /* Free resources */
    if (msg != NULL)
        gst_message_unref (msg);
    gst_object_unref (bus);
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
    return 0;
}

Build test.c

$ sudo apt-get install libgstreamer1.0-dev
$ gcc test.c -o test1 `pkg-config --cflags --libs gstreamer-1.0`

 

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

内容概要:本文针对功率阶跃工况下光储虚拟同步发电机(VSG)并网系统存在的电能质量问题,提出一种自适应治理策略。通过Simulink搭建完整的光储VSG并网系统仿真模型,重点研究在功率突变条件下系统出现的频率波动、电压畸变及谐波增加等动态问题。所提策略结合VSG的惯量与阻尼特性,设计了参数自适应调节机制,实现对系统动态响应过程的有效调控,显著提升了并网电流波形质量与频率稳定性,增强了系统在强扰动工况下的鲁棒性与电能质量治理能力。; 适合人群:具备电力电子、自动控制理论及新能源并网技术基础的科研人员、电气工程及相关专业的硕士/博士研究生,以及从事微电网、储能系统、VSG控制研发的工程技术人员。; 使用场景及目标:①用于分析光储系统在功率阶跃等动态工况下的并网特性与电能质量演变规律;②为VSG关键控制参数(如惯量、阻尼)的自适应整定提供设计思路与仿真验证平台;③支撑高水平学术论文复现、科研课题攻关及实际工程项目的前期控制策略验证。; 阅读建议:建议结合Simulink仿真模型深入理解控制策略的实现逻辑,重点关注VSG惯量阻尼协同调节的自适应机制设计,可通过设置不同功率阶跃幅度、光照强度变化及负载投切等多场景进行仿真测试,全面评估策略的动态性能与适用边界。
内容概要:本文系统研究了基于ARIMA-CNN-LSTM的混合时间序列预测模型,并提供了完整的Python代码实现。该模型融合传统统计方法ARIMA与深度学习模型CNN和LSTM的优势,充分发挥ARIMA在捕捉线性趋势与季节性特征方面的能力,以及CNN和LSTM在提取局部特征和建模长期依赖关系方面的强大性能,从而有效提升对复杂非线性时间序列的预测精度。研究涵盖了数据预处理、模型构建、参数调优、训练与预测全流程,并通过实际案例验证模型在风电、光伏、负荷、电价等能源领域预测任务中的优越表现。文档还整合了电力系统、路径规划、信号处理等多个科研方向的仿真资源与代码示例,凸显其在学术研究与工程实践中的广泛应用价值。; 适合人群:具备一定Python编程基础和机器学习理论知识,从事科研或工程技术工作的研究人员,特别适用于关注时间序列分析、深度学习建模的硕士生、博士生及行业从业者。; 使用场景及目标:①深入理解并掌握ARIMA与深度学习模型(如CNN、LSTM)融合的建模范式与技术细节;②应用于能源领域中风电出力、光伏发电、电力负荷及电价等关键变量的高精度预测;③为科研课题、学术论文复现、工程项目优化等提供可靠、可复用的代码框架与技术支持。; 阅读建议:建议结合所提供的Python代码进行动手实践,重点剖析数据预处理流程、混合模型架构设计及超参数调优策略,同时可参考文档中其他相关研究案例以拓宽技术视野和应用场景认知。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值