Getting corrupted images for different resolution
Posted: Tue Jan 05, 2016 3:32 pm
Hi all ,
I am using the c++ API to interface with the pi camera , works fine but there is an issue with it , i get corrupted images when in my resolution width is not divisible by 32 or height is not divisible by 16. For example when i give my resolution as 752 by 160 with 752 not being divisible by 32 i get a corrupted image. Works fine for resolutions like - 160 by 160 , 768 by 160 , 640 by 480 etc .
Create camera component function in the API
Is there any changes need to be made so that it works fine for all resolutions.
Thanks
I am using the c++ API to interface with the pi camera , works fine but there is an issue with it , i get corrupted images when in my resolution width is not divisible by 32 or height is not divisible by 16. For example when i give my resolution as 752 by 160 with 752 not being divisible by 32 i get a corrupted image. Works fine for resolutions like - 160 by 160 , 768 by 160 , 640 by 480 etc .
Create camera component function in the API
Code: Select all
MMAL_COMPONENT_T *Private_Impl::create_camera_component ( RASPIVID_STATE *state ) {
MMAL_COMPONENT_T *camera = 0;
MMAL_ES_FORMAT_T *format;
MMAL_PORT_T *video_port = NULL;
MMAL_STATUS_T status;
/* Create the component */
status = mmal_component_create ( MMAL_COMPONENT_DEFAULT_CAMERA, &camera );
if ( status != MMAL_SUCCESS ) {
cerr<< ( "Failed to create camera component" );
return 0;
}
if ( !camera->output_num ) {
cerr<< ( "Camera doesn't have output ports" );
mmal_component_destroy ( camera );
return 0;
}
video_port = camera->output[MMAL_CAMERA_VIDEO_PORT];
// set up the camera configuration
MMAL_PARAMETER_CAMERA_CONFIG_T cam_config;
cam_config.hdr.id=MMAL_PARAMETER_CAMERA_CONFIG;
cam_config.hdr.size=sizeof ( cam_config );
cam_config.max_stills_w = state->width;
cam_config.max_stills_h = state->height;
cam_config.stills_yuv422 = 0;
cam_config.one_shot_stills = 0;
cam_config.max_preview_video_w = state->width;
cam_config.max_preview_video_h = state->height;
cam_config.num_preview_video_frames = 3;
cam_config.stills_capture_circular_buffer_height = 0;
cam_config.fast_preview_resume = 0;
cam_config.use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RESET_STC;
mmal_port_parameter_set ( camera->control, &cam_config.hdr );
// Set the encode format on the video port
format = video_port->format;
format->encoding_variant = convertFormat ( State.captureFtm );
format->encoding = convertFormat ( State.captureFtm );
format->es->video.width = VCOS_ALIGN_UP(state->width, 32);
format->es->video.height = VCOS_ALIGN_UP(state->height, 16);
format->es->video.crop.x = 0;
format->es->video.crop.y = 0;
format->es->video.crop.width = state->width;
format->es->video.crop.height = state->height;
format->es->video.frame_rate.num = state->framerate;
format->es->video.frame_rate.den = VIDEO_FRAME_RATE_DEN;
status = mmal_port_format_commit ( video_port );
if ( status ) {
cerr<< ( "camera video format couldn't be set" );
mmal_component_destroy ( camera );
return 0;
}
// PR : plug the callback to the video port
status = mmal_port_enable ( video_port,video_buffer_callback );
if ( status ) {
cerr<< ( "camera video callback2 error" );
mmal_component_destroy ( camera );
return 0;
}
// Ensure there are enough buffers to avoid dropping frames
if ( video_port->buffer_num < VIDEO_OUTPUT_BUFFERS_NUM )
video_port->buffer_num = VIDEO_OUTPUT_BUFFERS_NUM;
//PR : create pool of message on video port
MMAL_POOL_T *pool;
video_port->buffer_size = video_port->buffer_size_recommended;
video_port->buffer_num = video_port->buffer_num_recommended;
pool = mmal_port_pool_create ( video_port, video_port->buffer_num, video_port->buffer_size );
if ( !pool ) {
cerr<< ( "Failed to create buffer header pool for video output port" );
}
state->video_pool = pool;
/* Enable component */
status = mmal_component_enable ( camera );
if ( status ) {
cerr<< ( "camera component couldn't be enabled" );
mmal_component_destroy ( camera );
return 0;
}
state->camera_component = camera;//this needs to be before set_all_parameters
return camera;
}Is there any changes need to be made so that it works fine for all resolutions.
Thanks