I’m tring to get raw data(YUV) from my camera and copy to cv::Mat(OpenCV).
I refer a sample of jetson multi media (10_camera_recording).
I’d like to get planes data from dma buffer. But my code shown as below does not worked.
Outpurt image is mosaiced.
How should I do ?
part of my code(in ConsumerThread::threadExecute())
int k=0; // in future, for-loop inpar.num_planes
NvBufferMemMap(dmabuf_fd, k, NvBufferMem_Read_Write, &ptr_top); //ptr_top is void*
NvBufferMemSyncForCpu(dmabuf_fd, k, &ptr_top);
uint32_t width = par.width[k];
uint32_t height = par.height[k];
uint32_t pitch = par.pitch[k];
uint32_t offset = par.offset[k];
printf("--buffer informaition-[%d]--\n", k);
printf("width :%4d\n", width);
printf("height:%4d\n", height);
printf("pitch :%4d\n", pitch);
printf("offset:%4d\n", offset);
printf("format:%4d\n", par.pixel_format);
cv::Mat src = cv::Mat::zeros(height, width, CV_8UC1);
ptr_cur = (uint8_t *)ptr_top; //ptr_cur is uint8_t *
for(int y =0;y < height; y++){
for(int x = 0; x < width; x++){
src.data[y*src.step+x + 0] = (uint8_t)(*ptr_cur);
ptr_cur++;
}
ptr_cur = (uint8_t *)ptr_top + pitch * y;
}
if(k==0){
cv::imwrite("Y.bmp", src);
}
else if(k==1){
cv::imwrite("UV.bmp",src);
}
else{
;
}
NvBufferMemSyncForDevice (dmabuf_fd, k, &ptr_top);
NvBufferMemUnMap(dmabuf_fd, k, &ptr_top);
Environment
HW : Jetson Xavier NX Devkit
SW : JetPack 4.4
Thank you.