资深版主
- 积分
- 2390
- 金钱
- 2390
- 注册时间
- 2019-9-25
- 在线时间
- 397 小时
|
本帖最后由 仰望星空之云 于 2024-6-14 15:38 编辑
1、查看摄像头的video节点
插入USB摄像头以后,多了一个media5节点:
- [root@ATK-DLRV1126:/demo/bin]# ls /dev/media*
- /dev/media0 /dev/media1 /dev/media2 /dev/media3 /dev/media4 /dev/media5
复制代码 查看media5的拓扑结构:
- [root@ATK-DLRV1126:/demo/bin]# media-ctl -p -d /dev/media5
- Media controller API version 4.19.111
- Media device information
- ------------------------
- driver uvcvideo
- model USB Camera: USB Camera
- serial
- bus info usb-ffe00000.usb-1.3
- hw revision 0x924
- driver version 4.19.111
- Device topology
- - entity 1: USB Camera: USB Camera (1 pad, 1 link)
- type Node subtype V4L flags 1
- device node name /dev/video45
- pad0: Sink
- <- "Extension 4":1 [ENABLED,IMMUTABLE]
- - entity 4: USB Camera: USB Camera (0 pad, 0 link)
- type Node subtype V4L flags 0
- device node name /dev/video46
- - entity 8: Extension 4 (2 pads, 2 links)
- type V4L2 subdev subtype Unknown flags 0
- pad0: Sink
- <- "Processing 3":1 [ENABLED,IMMUTABLE]
- pad1: Source
- -> "USB Camera: USB Camera":0 [ENABLED,IMMUTABLE]
- - entity 11: Processing 3 (2 pads, 2 links)
- type V4L2 subdev subtype Unknown flags 0
- pad0: Sink
- <- "Camera 1":0 [ENABLED,IMMUTABLE]
- pad1: Source
- -> "Extension 4":0 [ENABLED,IMMUTABLE]
- - entity 14: Camera 1 (1 pad, 1 link)
- type V4L2 subdev subtype Unknown flags 0
- pad0: Source
- -> "Processing 3":0 [ENABLED,IMMUTABLE]
复制代码 那么,USB摄像头的video节点是video45还是video46呢,可以用如下命令来查看:
- [root@ATK-DLRV1126:/demo/bin]# v4l2-ctl -d /dev/video45 --all
- Driver Info:
- Driver name : uvcvideo
- Card type : USB Camera: USB Camera
- Bus info : usb-ffe00000.usb-1.3
- Driver version : 4.19.111
- Capabilities : 0x84a00001
- Video Capture
- Metadata Capture
- Streaming
- Extended Pix Format
- Device Capabilities
- Device Caps : 0x04200001
- Video Capture
- Streaming
- Extended Pix Format
- Media Driver Info:
- Driver name : uvcvideo
- Model : USB Camera: USB Camera
- Serial :
- Bus info : usb-ffe00000.usb-1.3
- Media version : 4.19.111
- Hardware revision: 0x00000924 (2340)
- Driver version : 4.19.111
- Interface Info:
- ID : 0x03000002
- Type : V4L Video
- Entity Info:
- ID : 0x00000001 (1)
- Name : USB Camera: USB Camera
- Function : V4L2 I/O
- Flags : default
- Pad 0x01000007 : 0: Sink
- Link 0x02000010: from remote pad 0x100000a of entity 'Extension 4': Data, Enabled, Immutable
- Priority: 2
- Video input : 0 (Camera 1: ok)
- Format Video Capture:
- Width/Height : 640/480
- Pixel Format : 'MJPG' (Motion-JPEG)
- Field : None
- Bytes per Line : 0
- Size Image : 307200
- Colorspace : sRGB
- Transfer Function : Default (maps to sRGB)
- YCbCr/HSV Encoding: Default (maps to ITU-R 601)
- Quantization : Default (maps to Full Range)
- Flags :
- Crop Capability Video Capture:
- Bounds : Left 0, Top 0, Width 640, Height 480
- Default : Left 0, Top 0, Width 640, Height 480
- Pixel Aspect: 1/1
- Selection: crop_default, Left 0, Top 0, Width 640, Height 480, Flags:
- Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480, Flags:
- Streaming Parameters Video Capture:
- Capabilities : timeperframe
- Frames per second: 10.000 (10/1)
- Read buffers : 0
- brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
- contrast 0x00980901 (int) : min=0 max=100 step=1 default=0 value=0
- saturation 0x00980902 (int) : min=0 max=200 step=1 default=90 value=90
- hue 0x00980903 (int) : min=-180 max=180 step=1 default=0 value=0
- white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1
- gamma 0x00980910 (int) : min=40 max=220 step=1 default=70 value=70
- power_line_frequency 0x00980918 (menu) : min=0 max=2 default=2 value=1
- white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=1 default=5000 value=6480 flags=inactive
- sharpness 0x0098091b (int) : min=0 max=10 step=1 default=4 value=4
- backlight_compensation 0x0098091c (int) : min=0 max=5 step=1 default=0 value=0
- exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=3
- exposure_absolute 0x009a0902 (int) : min=10 max=5000 step=1 default=2500 value=2500 flags=inactive
- zoom_absolute 0x009a090d (int) : min=0 max=50 step=1 default=0 value=0
复制代码 看到video45有像素格式,那么,USB摄像头应该使用的是video45
2、V4L2采集图像
查看video节点格式
先查看video45节点只支持的所有像素格式和分辨率吧:
- [root@ATK-DLRV1126:/demo/bin]# v4l2-ctl -d /dev/video45 --list-formats
- ioctl: VIDIOC_ENUM_FMT
- Type: Video Capture
- [0]: 'MJPG' (Motion-JPEG, compressed)
- [1]: 'YUYV' (YUYV 4:2:2)
-
- [root@ATK-DLRV1126:/demo/bin]# v4l2-ctl -d /dev/video45 --list-formats-ext
- ioctl: VIDIOC_ENUM_FMT
- Type: Video Capture
- [0]: 'MJPG' (Motion-JPEG, compressed)
- Size: Discrete 640x480
- Interval: Stepwise 0.033s - 1.000s with step 0.033s (1.000-30.000 fps)
- Size: Discrete 320x240
- Interval: Stepwise 0.033s - 1.000s with step 0.033s (1.000-30.000 fps)
- Size: Discrete 160x120
- Interval: Stepwise 0.033s - 1.000s with step 0.033s (1.000-30.000 fps)
- Size: Discrete 176x144
- Interval: Stepwise 0.033s - 1.000s with step 0.033s (1.000-30.000 fps)
- Size: Discrete 352x288
- Interval: Stepwise 0.033s - 1.000s with step 0.033s (1.000-30.000 fps)
- [1]: 'YUYV' (YUYV 4:2:2)
- Size: Discrete 640x480
- Interval: Discrete 0.033s (30.000 fps)
- Interval: Discrete 0.050s (20.000 fps)
- Interval: Discrete 0.067s (15.000 fps)
- Interval: Discrete 0.100s (10.000 fps)
- Interval: Discrete 0.200s (5.000 fps)
- Interval: Discrete 1.000s (1.000 fps)
- Size: Discrete 320x240
- Interval: Discrete 0.033s (30.000 fps)
- Interval: Discrete 0.050s (20.000 fps)
- Interval: Discrete 0.067s (15.000 fps)
- Interval: Discrete 0.100s (10.000 fps)
- Interval: Discrete 0.102s (9.833 fps)
- Interval: Discrete 1.000s (1.000 fps)
- Size: Discrete 160x120
- Interval: Discrete 0.033s (30.000 fps)
- Interval: Discrete 0.050s (20.000 fps)
- Interval: Discrete 0.067s (15.000 fps)
- Interval: Discrete 0.100s (10.000 fps)
- Interval: Discrete 0.102s (9.833 fps)
- Interval: Discrete 1.000s (1.000 fps)
- Size: Discrete 176x144
- Interval: Discrete 0.033s (30.000 fps)
- Interval: Discrete 0.050s (20.000 fps)
- Interval: Discrete 0.067s (15.000 fps)
- Interval: Discrete 0.100s (10.000 fps)
- Interval: Discrete 0.102s (9.833 fps)
- Interval: Discrete 1.000s (1.000 fps)
- Size: Discrete 352x288
- Interval: Discrete 0.033s (30.000 fps)
- Interval: Discrete 0.050s (20.000 fps)
- Interval: Discrete 0.067s (15.000 fps)
- Interval: Discrete 0.100s (10.000 fps)
- Interval: Discrete 0.102s (9.833 fps)
- Interval: Discrete 1.000s (1.000 fps)
- [root@ATK-DLRV1126:/demo/bin]#
复制代码 可以看到,支持YUYV 4:2:2,640x480大小,那么我们就采集这个格式的视频吧。
采集图像
- v4l2-ctl -d /dev/video45 \
- --set-fmt-video=width=640,height=480,\
- pixelformat=YUYV \
- --stream-mmap=3 \
- --stream-skip=3 \
- --stream-to=/tmp/cif.raw \
- --stream-count=1 \
- --stream-poll
复制代码 使用adb命令拷贝到ubuntu下查看,ubuntu下执行命令:
- adb pull /tmp/cif.raw .
- ffplay -f rawvideo -s 640x480 -pix_fmt yuyv422 cif.raw
复制代码 可以看到图片,v4l2能抓到图。
3、使用RKMedia采集图像
rkmedia_vi_vo代码改写
- // Copyright 2020 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include <assert.h>
- #include <fcntl.h>
- #include <getopt.h>
- #include <signal.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <unistd.h>
- #include "common/sample_common.h"
- #include "rkmedia_api.h"
- static bool quit = false;
- static void sigterm_handler(int sig) {
- fprintf(stderr, "signal %d\n", sig);
- quit = true;
- }
- static RK_CHAR optstr[] = "?::a::I:h:w:M:";
- static const struct option long_options[] = {
- {"aiq", optional_argument, NULL, 'a'},
- {"camid", required_argument, NULL, 'I'},
- {"multictx", required_argument, NULL, 'M'},
- {"help", optional_argument, NULL, '?'},
- {NULL, 0, NULL, 0},
- };
- static void print_usage(const RK_CHAR *name) {
- printf("usage example:\n");
- #ifdef RKAIQ
- printf("\t%s [-a [iqfiles_dir]]"
- "[-I 0] "
- "[-M 0] "
- "\n",
- name);
- printf("\t-a | --aiq: enable aiq with dirpath provided, eg:-a "
- "/oem/etc/iqfiles/, "
- "set dirpath empty to using path by default, without this option aiq "
- "should run in other application\n");
- printf("\t-M | --multictx: switch of multictx in isp, set 0 to disable, set "
- "1 to enable. Default: 0\n");
- #else
- printf("\t%s [-I 0]\n", name);
- #endif
- printf("\t-I | --camid: camera ctx id, Default 0\n");
- printf("\t-w: DisplayWidth, Default: 720\n");
- printf("\t-h: DisplayHeight, Default: 1280\n");
- }
- int main(int argc, char *argv[]) {
- int ret = 0;
-
- /*int video_width = 1920;
- int video_height = 1080;
-
- int disp_width = 720;
- int disp_height = 1280;*/
- RK_S32 s32CamId = 0;
- #ifdef RKAIQ
- RK_BOOL bMultictx = RK_FALSE;
- #endif
- int c;
- char *iq_file_dir = NULL;
- while ((c = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) {
- const char *tmp_optarg = optarg;
- switch (c) {
- case 'a':
- if (!optarg && NULL != argv[optind] && '-' != argv[optind][0]) {
- tmp_optarg = argv[optind++];
- }
- if (tmp_optarg) {
- iq_file_dir = (char *)tmp_optarg;
- } else {
- iq_file_dir = "/oem/etc/iqfiles";
- }
- break;
- case 'I':
- s32CamId = atoi(optarg);
- break;
- case 'w':
- //disp_width = atoi(optarg);
- break;
- case 'h':
- //disp_height = atoi(optarg);
- break;
- #ifdef RKAIQ
- case 'M':
- if (atoi(optarg)) {
- bMultictx = RK_TRUE;
- }
- break;
- #endif
- case '?':
- default:
- print_usage(argv[0]);
- return 0;
- }
- }
- printf("#CameraIdx: %d\n\n", s32CamId);
- if (iq_file_dir) {
- #ifdef RKAIQ
- printf("#Rkaiq XML DirPath: %s\n", iq_file_dir);
- printf("#bMultictx: %d\n\n", bMultictx);
- rk_aiq_working_mode_t hdr_mode = RK_AIQ_WORKING_MODE_NORMAL;
- int fps = 30;
- SAMPLE_COMM_ISP_Init(s32CamId, hdr_mode, bMultictx, iq_file_dir);
- SAMPLE_COMM_ISP_Run(s32CamId);
- SAMPLE_COMM_ISP_SetFrameRate(s32CamId, fps);
- #endif
- }
- RK_MPI_SYS_Init();
- VI_CHN_ATTR_S vi_chn_attr;
- vi_chn_attr.pcVideoNode = "/dev/video45";
- vi_chn_attr.u32BufCnt = 3;
- vi_chn_attr.u32Width = 640;
- vi_chn_attr.u32Height = 480;
- vi_chn_attr.enPixFmt = IMAGE_TYPE_YUYV422;
- vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
- ret = RK_MPI_VI_SetChnAttr(s32CamId, 0, &vi_chn_attr);
- ret |= RK_MPI_VI_EnableChn(s32CamId, 0);
- if (ret) {
- printf("Create vi[0] failed! ret=%d\n", ret);
- return -1;
- }
- /* test rgn cover */
- COVER_INFO_S CoverInfo;
- OSD_REGION_INFO_S RngInfo;
- memset(&CoverInfo, 0, sizeof(CoverInfo));
- memset(&RngInfo, 0, sizeof(RngInfo));
- CoverInfo.enPixelFormat = PIXEL_FORMAT_ARGB_8888;
- CoverInfo.u32Color = 0xFFFF0000; // blue
- RngInfo.enRegionId = REGION_ID_0;
- RngInfo.u32PosX = 0;
- RngInfo.u32PosY = 0;
- RngInfo.u32Width = 100;
- RngInfo.u32Height = 100;
- RngInfo.u8Enable = 1;
- RK_MPI_VI_RGN_SetCover(s32CamId, 1, &RngInfo, &CoverInfo);
- // rga0 for primary plane
- RGA_ATTR_S stRgaAttr;
- memset(&stRgaAttr, 0, sizeof(stRgaAttr));
- stRgaAttr.bEnBufPool = RK_TRUE;
- stRgaAttr.u16BufPoolCnt = 3;
- stRgaAttr.u16Rotaion = 90;
- stRgaAttr.stImgIn.u32X = 0;
- stRgaAttr.stImgIn.u32Y = 0;
- stRgaAttr.stImgIn.imgType = IMAGE_TYPE_YUYV422;
- stRgaAttr.stImgIn.u32Width = 640;
- stRgaAttr.stImgIn.u32Height = 480;
- stRgaAttr.stImgIn.u32HorStride = 640;
- stRgaAttr.stImgIn.u32VirStride = 480;
- stRgaAttr.stImgOut.u32X = 0;
- stRgaAttr.stImgOut.u32Y = 0;
- stRgaAttr.stImgOut.imgType = IMAGE_TYPE_RGB888;
- stRgaAttr.stImgOut.u32Width = 640;
- stRgaAttr.stImgOut.u32Height = 480;
- stRgaAttr.stImgOut.u32HorStride = 640;
- stRgaAttr.stImgOut.u32VirStride = 480;
- ret = RK_MPI_RGA_CreateChn(0, &stRgaAttr);
- if (ret) {
- printf("Create rga[0] falied! ret=%d\n", ret);
- return -1;
- }
- VO_CHN_ATTR_S stVoAttr = {0};
- // VO[0] for primary plane
- stVoAttr.pcDevNode = "/dev/dri/card0";
- stVoAttr.emPlaneType = VO_PLANE_PRIMARY;
- stVoAttr.enImgType = IMAGE_TYPE_RGB888;
- stVoAttr.u16Zpos = 0;
- stVoAttr.stImgRect.s32X = 0;
- stVoAttr.stImgRect.s32Y = 0;
- stVoAttr.stImgRect.u32Width = 640;
- stVoAttr.stImgRect.u32Height = 480;
- stVoAttr.stDispRect.s32X = 0;
- stVoAttr.stDispRect.s32Y = 0;
- stVoAttr.stDispRect.u32Width = 640;
- stVoAttr.stDispRect.u32Height = 480;
- ret = RK_MPI_VO_CreateChn(0, &stVoAttr);
- if (ret) {
- printf("Create vo[0] failed! ret=%d\n", ret);
- return -1;
- }
- MPP_CHN_S stSrcChn = {0};
- MPP_CHN_S stDestChn = {0};
- printf("#Bind VI[0] to RGA[0]....\n");
- stSrcChn.enModId = RK_ID_VI;
- stSrcChn.s32ChnId = 0;
- stDestChn.enModId = RK_ID_RGA;
- stDestChn.s32ChnId = 0;
- ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
- if (ret) {
- printf("Bind vi[0] to rga[0] failed! ret=%d\n", ret);
- return -1;
- }
- printf("# Bind RGA[0] to VO[0]....\n");
- stSrcChn.enModId = RK_ID_RGA;
- stSrcChn.s32ChnId = 0;
- stDestChn.enModId = RK_ID_VO;
- stDestChn.s32ChnId = 0;
- ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
- if (ret) {
- printf("Bind rga[0] to vo[0] failed! ret=%d\n", ret);
- return -1;
- }
- printf("%s initial finish\n", __func__);
- signal(SIGINT, sigterm_handler);
- while (!quit) {
- usleep(500000);
- }
- printf("%s exit!\n", __func__);
- stSrcChn.enModId = RK_ID_VI;
- stSrcChn.s32ChnId = 0;
- stDestChn.enModId = RK_ID_RGA;
- stDestChn.s32ChnId = 0;
- ret = RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
- if (ret) {
- printf("UnBind vi[0] to rga[0] failed! ret=%d\n", ret);
- return -1;
- }
- stSrcChn.enModId = RK_ID_RGA;
- stSrcChn.s32ChnId = 0;
- stDestChn.enModId = RK_ID_VO;
- stDestChn.s32ChnId = 0;
- ret = RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
- if (ret) {
- printf("UnBind rga[0] to vo[0] failed! ret=%d\n", ret);
- return -1;
- }
- RK_MPI_VO_DestroyChn(0);
- RK_MPI_RGA_DestroyChn(0);
- RK_MPI_VI_DisableChn(s32CamId, 0);
- if (iq_file_dir) {
- #ifdef RKAIQ
- SAMPLE_COMM_ISP_Stop(s32CamId);
- #endif
- }
- return 0;
- }
复制代码 测试方法
- ./rkmedia_vi_vo_test -a /etc/iqfiles/
复制代码 最终,屏幕上可以显示USB摄像头采集的图像。
关于rkmedia的使用,可以去看SDK中的rkmedia的例子,API说明可以看RK提供的《Rockchip_Developer_Guide_Linux_RKMedia_CN.pdf》,视频教程可以看《【正点原子】AI人工智能深度学习(RV1126/RK3568/RK3588)-第2期 提高篇》
|
-
-
|