|
发表于 2019-10-11 11:17:10
|
显示全部楼层
本帖最后由 shopping 于 2019-10-11 11:30 编辑
老哥,用RGA转换格式出现花屏重影的问题。我自己写了个 yuv422 转 BGR 的函数,结果显示正常,RGA sample demo :https://github.com/Jerzha/samples-toybrick-rga .
- // rga start
- srcBuffer = (unsigned char*)malloc(sizeof(unsigned char) * BUFFER_SIZE_src); // yuyv BUFFER_SIZE_src = MAGE_WIDTH*IMAGE_HEIGHT*2
- dstBuffer = (unsigned char*)malloc(sizeof(unsigned char) * BUFFER_SIZE_det); // RGB BUFFER_SIZE_det = MAGE_WIDTH*IMAGE_HEIGHT*3
- RockchipRga *mRga = RgaCreate();
- if (!mRga) {
- printf("create rga failed !\n");
- abort();
- }
- mRga->ops->initCtx(mRga);
- mRga->ops->setSrcFormat(mRga, V4L2_PIX_FMT_YUYV, IMAGE_WIDTH, IMAGE_HEIGHT);
- mRga->ops->setDstFormat(mRga, V4L2_PIX_FMT_BGR24, IMAGE_WIDTH, IMAGE_HEIGHT);
- struct v4l2_buffer enqueue,dequeue ;
- memset(&enqueue, 0, sizeof(enqueue));
- memset(&dequeue, 0, sizeof(dequeue));
- enqueue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
- enqueue.memory = V4L2_MEMORY_MMAP ;
- dequeue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
- dequeue.memory = V4L2_MEMORY_MMAP ;
- while (1)
- {
- // loop start
- // dequeue
- ioctl(fd, VIDIOC_DQBUF, &dequeue) ; // get frame v4l2取缓存帧
- //memcpy((void*)srcBuffer , buffers[dequeue.index].start , dequeue.length);
- srcBuffer = (unsigned char *)buffers[dequeue.index].start; // 将取出来的缓存帧起始地址赋给 srcBuffer
- mRga->ops->setSrcBufferPtr(mRga, srcBuffer);
- mRga->ops->setDstBufferPtr(mRga, dstBuffer);
- mRga->ops->go(mRga);
- unchar_to_Mat(dstBuffer); // 将 unsigned char BGR格式转换为 Mat BGR格式
- cv::imshow("image",img);
- cv::waitKey(20);
- //enqueue
- enqueue.index = dequeue.index ;
- ioctl(fd, VIDIOC_QBUF, &enqueue) ; // enqueue
- }
- ioctl(fd, VIDIOC_STREAMOFF, &type);
- free(srcBuffer);
- free(dstBuffer);
- for(int i=0;i<req.count;i++)
- {
- munmap(buffers[i].start,buffers[i].length);
- }
- return(TRUE);
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|