完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
前期准备
需要以下设备: 1、Toybrick TB-RK3399ProD开发板 2、USB摄像头(Logitech Webcam C270) 3、HDMI显示器、USB鼠标/键盘、以太网线缆 一、操作系统 我用的TB-RK3399ProD开发板跑的操作系统是烧写的Toybrick官方提供的Debian10固件(Toybrick社区重点维护) 二、开发环境搭建 1、软件升级 sudo apt update sudo apt upgrade 2、drm、rga、mpp安装 sudo apt install rockchip-drm-dev libdrm-dev sudo apt install rockchip-rga-dev sudo apt install rockchip-mpp-dev 3、ISP安装 sudo apt install rockchip-isp 4、OpenCV安装: sudo apt-get update sudo apt install libopencv-dev 注:安装后的头文件目录:/usr/include/rockchip、库目录:/usr/lib/aarch64-linux-gnu、example目录:/usr/share/rockchip-xxx 三、功能实现 本功能的是基于上面几个库的example例程参考实现的 1、USB camera的V4L2图像采集参考:/usr/share/rockchip-isp/example/example.cpp 2、V4L2采集的图像调用RKMPP编码参考:/usr/share/rockchip-mpp/example/mpp_encode.cpp 3、OpenCV要播放V4L2获取的图像,需要先用RKRGA图像加速库把视频格式转换成V4L2_PIX_FMT_RGB24,参考:/usr/share/rockchip-rga/example/rga_convert.cpp 四、主体源码 源码编译:源码是放到板子进行编译的 源码增加了三个宏开关,如下: #define RK_MPP_ENC 1 //使用RKMPP编码并存储到H264文件宏开关功能源码主要部分如下: int camera(char *dev, __u32 w, __u32 h, RgaRotate r, int V, int H, __u32 cx, __u32 cy, __u32 cw, __u32 ch, CameraType type, __u32 f) { int ret = 0; int frames = PLAY_FRAMES; v4l2_camera camera; rockchip_rga rga; Mat mat; FILE *fp = NULL; FILE *fp_h264 = NULL; #if RK_SAVE_YUYV /* Save to file */ if(f == V4L2_PIX_FMT_YUYV) fp = fopen("test.yuyv", "w+"); else if(f == V4L2_PIX_FMT_YUV420) fp = fopen("test.yuv420", "w+"); else fp = fopen("test.unknown", "w+"); if (fp == NULL) return -EIO; #endif #if RK_OPENCV_SHOW cv::namedWindow(winname); cv::moveWindow(winname, w, h); mat.create(cv::Size(RGA_ALIGN(w, 16), RGA_ALIGN(h, 16)), CV_8UC3); ret = rga.init(); if(ret < 0) goto exit; #endif /* TODO: Init camera deivce */ ret = camera.init(dev, type); if(ret < 0) goto exit; /* TODO: Set picture format */ ret = camera.setfmt(w, h, f); if(ret < 0) goto exit; /* TODO: Request and mmap buffers */ ret = camera.reqbufs_mmap(4); if(ret < 0) goto exit; /* TODO: Start stream capture */ ret = camera.start(); if(ret < 0) goto exit; #if RK_MPP_ENC fp_h264 = fopen("test.h264", "w+"); ret = mpp_enc_init(fp_h264, f, w, h); if(ret < 0) goto exit; #endif while(frames--) { int index; size_t len = 0; void *buf = NULL; unsigned long long t1, t2, t3, t4; #if RK_OPENCV_SHOW struct rga_format src_fmt, dst_fmt; struct rga_crop crop; src_fmt.width = w; src_fmt.height = h; src_fmt.format = f; dst_fmt.width = w; dst_fmt.height = h; dst_fmt.format = V4L2_PIX_FMT_RGB24; crop.x = cx; crop.y = cy; crop.h = ch; crop.w = cw; #endif t1 = nanoTime(); /* TODO: Dequeue buffer */ buf = camera.dequeue(&index, &len); #if RK_MPP_ENC mpp_enc(fp_h264, buf, len); #endif #if RK_SAVE_YUYV fwrite(buf, len, 1, fp); #endif t2 = nanoTime(); #if RK_OPENCV_SHOW ret = rga.convert(buf, mat.data, src_fmt, dst_fmt, crop, r); if(ret < 0) goto exit; #endif /* TODO: Enqueue buffer */ camera.enqueue(index); t3 = nanoTime(); #if RK_OPENCV_SHOW imshow(winname, mat); cv::waitKey(1); #endif t4 = nanoTime(); printf("Picture size %llu, dequeue time %llums, enqueue time: %llums, display time: %llumsn", len, (t2 - t1) / 1000000, (t3 - t2) / 1000000, (t4 - t3) / 1000000); } exit: #if RK_MPP_ENC mpp_enc_unit(); if(fp_h264 != NULL) fclose(fp_h264); #endif #if RK_SAVE_YUYV if(fp != NULL) fclose(fp); #endif return ret; } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1443 浏览 1 评论
synopsys 的design ware:DW_fpv_div,浮点数除法器,默认32位下,想提升覆盖率(TMAX),如果用功能case去提升覆盖率呢?
1570 浏览 1 评论
RK3588 GStreamer调试四路鱼眼摄像头四宫格显示报错
3581 浏览 1 评论
【飞凌嵌入式OK3576-C开发板体验】RKNN神经网络-YOLO图像识别
254 浏览 0 评论
【飞凌嵌入式OK3576-C开发板体验】SSH远程登录网络配置及CAN通讯
1336 浏览 0 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-6 05:40 , Processed in 0.595928 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号