I’m currently developing with DPX2 base on Driveworks 5.0.5.0a using Driveworks Version6.0. I have a question about extracting image data array of RGBA format from dwImageCPU.
Here, dwImage_streamer is used for posting dwImageNVMEDIA to dwImageCPU (dwImageType of dwImageNVMEDIA has already covert to RGBA through an ImageFormatCoverter), in this way, we can extract the uint8_t * image data array from the dwImageCPU struct theoretically. But we got an data array of size 0(which means there is no handle pointing to any Rgba image data array in dwImageCPU>>(uint8_t ) data[DW_MAX_IMAGE_PLANES]). By the way, we have already confirmed that the input dwImageNVMEDIA is valid by passing through a dwImage_streamer to dw_Image_GL, and receiving display successfully. More to mention, both dwImageStreamer_postNVMEDIA and dwImageStreamer_receiveCPU resulted as DW_SUCCESS.
Is there some determinant parameter causing this error? And what is the difference between DW_CAMERA_PROCESSED_IMAGE and DW_CAMERA_RAW_IMAGE in dwCameraOutputType while using function dwSensorCamera_getImageProperties? Will it be the key point of initializing dwImage_streamer?
Dear chaofanyin,
DW_CAMERA_RAW_IMAGE captures the image in RAW format, DW_CAMERA_PROCESSED_IMAGE captures image in processed(yuv) format. Have you checked printing data[0] array? can you double check dwImageProperties of dwImageCPU?
I believe, you have captured image DW_CAMERA_PROCESSED_IMAGE flag and used dwImageFormatConverter_copyConvertNvMedia to convert to RGBA format before sending it to CPU using imageStreamer.
Thank you for your quick reply. And I do process the image frame as you described. I have double checked the dwImageProperties of dwImageCPU, and the properties seem to be normal(type=0[dwImageCPU], width=1280, height=1080, pixelFormat=3000[RGBA],pxlType=64).By the way, the image size should be 12801080,however dwImageCPU.pitch[0] equals to 5120(which should be 12801080*4), and data[0] prints to be empty.
Did something wrong? Or is there any other way to extract the RGBA image and save it?
Dear chaofanyin,
We will look into it. Can you quickly check printing data[0], data[1]… before writing it to file. Also, I do not see any dwImageFormatConverter_copyConvertNvMedia calls in the code as you mentioned.
Dear chaofanyin,
I have modified camera_gsml sample to get camera image as RGBA values on CPU side. I have replaced GL consumer with CPU consumer. I am sharing the code snippet below.
if (status != DW_SUCCESS) {
std::cout << "\n ERROR postNvMedia: " << dwGetStatusName(status) << std::endl;
} else {
dwImageCPU *frameCPU = nullptr;
std::string filename;
status = dwImageStreamer_receiveCPU(&frameCPU, 60000, nvm2gl);
if (status == DW_SUCCESS && frameCPU) {
std::cout << "\nsizeofdata: " << ((char*)(frameCPU->data[0])) << "\n";
std::cout << "sizeofpitch: " << frameCPU->pitch[0] << "\n";
std::cout<<"type "<<frameCPU->prop.type;
std::cout<<"width "<<frameCPU->prop.width;
std::cout<<"height "<<frameCPU->prop.height;
std::cout<<"dwImagePixelFormat "<<frameCPU->prop.pxlFormat;
std::cout<<"dwTrivialDataType "<<frameCPU->prop.pxlType<< "\n";
memcpy(RGBAarray,(char*)(frameCPU->data[0]),frameCPU->prop.width * frameCPU->prop.height * sizeof(char));
filename = std::to_string(count)+ std::string("_Image.txt");
FILE *fp=fopen(filename.c_str(),"w+");
fprintf(fp, "%s", RGBAarray);
fclose(fp);
count++;
dwImageStreamer_returnReceivedCPU(frameCPU, nvm2gl);
}
}
// any image returned back, we put back into the pool
dwImageNvMedia *retimg = nullptr;
dwImageStreamer_waitPostedNvMedia(&retimg, 33000, nvm2gl);
Looks like you are trying to copy 128010804 values. It has to be 1280*1080(frameCPU->prop.width * frameCPU->prop.height). I hope this helps.