rk3399 opencv测试cpu跟gpu性能

rk3399的gpu测试节点在:

cat /sys/devices/platform/ff9a0000.gpu/devfreq/ff9a0000.gpu/load

如果没有使用gpu的话,是显示0@200000000Hz,0就是使用率占0%

参考下opencv官网的文档:https://opencv.org/platforms/opencl.html

我们打开摄像头 进行灰阶并高斯模糊处理为例子

1.使用CPU操作:

代码:

#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char **argv)
{
    int64 start=0,end=0;
    VideoCapture vcap(0);
    Mat frame, frameGray;
    for(;;){
        start = getTickCount();
        vcap >> frame;
        cvtColor(frame, frameGray, CV_BGR2GRAY);
        GaussianBlur(frameGray, frameGray, Size(3,3), 0,0);
        end = getTickCount();
        printf("time: %f ms\n", 1000.0*(end -start)/getTickFrequency());
     }
    return 0;
}

运行如下:

代码执行如下:
time: 33.082281 ms
time: 32.365384 ms
time: 34.381331 ms
time: 31.857022 ms
time: 33.016366 ms
time: 36.259030 ms
time: 30.849634 ms

CPU如下:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16972 pi 20 0 504792 44632 26112 R 110.5 1.1 0:14.98 cpu

GPU如下:
0@200000000Hz
0@200000000Hz
0@200000000Hz

 

2使用GPU

代码:

#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
//opencl
#include <opencv2/core/ocl.hpp>
using namespace std;
using namespace cv;
int main(int argc, char **argv)
{
    ocl::setUseOpenCL(true);
    VideoCapture vcap(0);
    UMat frame, frameGray;
    int64 start=0,end=0;
    for(;;){
        start = getTickCount();
        vcap >> frame;
        cvtColor(frame, frameGray, CV_BGR2GRAY);
        GaussianBlur(frameGray,frameGray , Size(3,3), 0,0);
        end = getTickCount();
        printf("time: %f ms\n", 1000.0*(end - start)/getTickFrequency());
    }
    return 0;
}

运行如下:

代码执行如下:
time: 42.600703 ms
time: 39.476152 ms
time: 43.411226 ms
time: 43.945546 ms
time: 43.886631 ms
time: 39.469735 ms
time: 44.085834 ms
time: 43.899755 ms
time: 39.333239 ms
time: 41.394690 ms
time: 40.303882 ms
time: 40.037888 ms
CPU如下: PID USER PR NI VIRT RES SHR S
%CPU %MEM TIME+ COMMAND 17913 root 20 0 455452 66108 42952 S 62.9 1.7 0:06.04 cl GPU如下: 24@200000000Hz 34@200000000Hz 42@200000000Hz 40@200000000Hz 38@200000000Hz 36@200000000Hz 39@200000000Hz 36@200000000Hz

 

关于opencv编译我之前已经说过,如果想编译简单点,就在cmake时候 将-D BUILD_opencv_world=YES加上,

编译命令:g++ -o cpu cpu.cpp  -I/usr/local/opencv_rk3399/include -L/usr/local/opencv_rk3399/lib/ -lopencv_world

rk3399 个人测下来感觉gpu处理跟cpu处理速度并不明显,而且GPU有时候还有点稍慢。并没有JETSON TX2这种板子那么明显。

 

posted @ 2019-01-23 14:23  yydsLinux  阅读(4403)  评论(0编辑  收藏  举报