Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

libgphoto2 convert char* to cv::Mat

I am using libgphoto2 to get images from a still camera, and I am not able to convert the images into cv::Mat data type. The image from the camera is stored as char*, and when I convert the image, the image is solid blue. This is the code I have for the conversion.

cv::Mat tempMat = cv::Mat(3456, 5184, CV_8UC3, (unsigned char) *data);

I am able to write the data to a file and reload in the image in opencv, but I don't want to save and load from file every time I capture an image.

libgphoto2 convert char* to cv::Mat

I am using libgphoto2 to get images from a still camera, and I am not able to convert the images into cv::Mat data type. The image from the camera is stored as char*, and when I convert the image, the image is solid blue. This is the relevant code I have for the conversion.question.

Camera *camera; 
gp_camera_new (&camera);
GPContext *context = gp_context_new();

char *data;
unsigned long size;
FILE *f;
capture_to_memory(camera, context, (const char**)&data, &size);

f = fopen("foo2.jpg", "wb");
retval=fwrite(data, size, 1, f);
fclose(f);

cv::Mat tempMat = cv::Mat(3456, 5184, CV_8UC3, (unsigned char) *data);

I am able to write the data to a file and reload in the image in opencv, but I don't want to save and load from file every time I capture an image.

libgphoto2 convert char* to cv::Mat

I am using libgphoto2 to get images from a still camera, and I am not able to convert the images into cv::Mat data type. The image from the camera is stored as char*, and when I convert the image, the image is solid blue. This is the relevant code I have for the question.

Camera *camera; 
gp_camera_new (&camera);
GPContext *context = gp_context_new();

char *data;
unsigned long size;
FILE *f;
capture_to_memory(camera, context, (const char**)&data, &size);

f = fopen("foo2.jpg", "wb");
retval=fwrite(data, size, 1, f);
fclose(f);

cv::Mat tempMat = cv::Mat(3456, 5184, CV_8UC3, (unsigned char) *data);

I am able to write the data to a file and reload in the image in opencv, but I don't want to save and load from file every time I capture an image.