c - Issues with libdc1394 -
i trying images point grey firewire 1394 camera using libdc1394. here code.
#include <stdio.h> #include <stdint.h> #include <dc1394/dc1394.h> #include <stdlib.h> #include <inttypes.h> #ifndef _win32 #include <unistd.h> #endif #define image_file_name "image.ppm" /*----------------------------------------------------------------------- * releases cameras , exits *-----------------------------------------------------------------------*/ void cleanup_and_exit(dc1394camera_t *camera) { dc1394_video_set_transmission(camera, dc1394_off); dc1394_capture_stop(camera); dc1394_camera_free(camera); exit(1); } int main(int argc, char *argv[]) { file* imagefile; dc1394camera_t *camera; unsigned int width, height; dc1394video_frame_t *frame=null; //dc1394featureset_t features; dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; d = dc1394_new (); if (!d) return 1; err=dc1394_camera_enumerate (d, &list); dc1394_err_rtn(err,"failed enumerate cameras"); if (list->num == 0) { dc1394_log_error("no cameras found"); return 1; } camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { dc1394_log_error("failed initialize camera guid %llx", list->ids[0].guid); return 1; } dc1394_camera_free_list (list); printf("using camera guid %"prix64"\n", camera->guid); /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ err=dc1394_video_set_operation_mode(camera, dc1394_operation_mode_1394b); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not set 1394b mode"); err=dc1394_video_set_iso_speed(camera, dc1394_iso_speed_800); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not set iso speed"); err=dc1394_video_set_mode(camera, dc1394_video_mode_format7_0); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not set video mode\n"); err=dc1394_format7_set_roi(camera, dc1394_video_mode_format7_0, dc1394_color_coding_raw16, dc1394_use_max_avail, 0, 0, 1024, 726); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not roi\n"); err=dc1394_capture_setup(camera,4, dc1394_capture_flags_default); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not setup camera-\nmake sure video mode , framerate are\nsupported camera\n"); /*----------------------------------------------------------------------- * gijs edit: show f7 info *-----------------------------------------------------------------------*/ uint32_t unit_bytes; uint32_t max_bytes; err=dc1394_format7_get_packet_parameters(camera, dc1394_video_mode_format7_0, &unit_bytes, &max_bytes ); printf("\n[debug] f7 info\n"); printf("[debug] unit_byte: %d (error %d)\n", unit_bytes, err ); printf("[debug] max_bytes: %d (error %d)\n", max_bytes, err ); uint32_t packet_size; err=dc1394_format7_get_packet_size(camera, dc1394_video_mode_format7_0, &packet_size ); printf("[debug] packet_size: %d (error %d)\n", packet_size, err ); uint32_t packets_per_frame; err=dc1394_format7_get_packets_per_frame(camera, dc1394_video_mode_format7_0, &packets_per_frame ); printf("[debug] packets_per_frame: %d (error %d)\n", packets_per_frame, err ); uint32_t pixels_per_frame; err=dc1394_format7_get_pixel_number(camera, dc1394_video_mode_format7_0, &pixels_per_frame ); printf("[debug] pixels_per_frame: %d (error %d)\n", pixels_per_frame, err ); uint32_t recommended_packet_size; err=dc1394_format7_get_recommended_packet_size(camera, dc1394_video_mode_format7_0, &recommended_packet_size ); printf("[debug] recommended_packet_size: %d (error %d)\n", recommended_packet_size, err ); uint32_t total_bytes; err=dc1394_format7_get_total_bytes(camera, dc1394_video_mode_format7_0, &total_bytes ); printf("[debug] total_size: %d (error %d)\n", total_bytes, err ); /*----------------------------------------------------------------------- * have camera start sending data *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera, dc1394_on); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not start camera iso transmission\n"); /*----------------------------------------------------------------------- * capture 1 frame *-----------------------------------------------------------------------*/ err=dc1394_capture_dequeue(camera, dc1394_capture_policy_wait, &frame); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not capture frame\n"); /*----------------------------------------------------------------------- * check if frame corrupt *-----------------------------------------------------------------------*/ printf("\n[debug] frame corrupt: "); if( dc1394_capture_is_frame_corrupt( camera, frame) ) printf("yes\n"); else printf("no\n"); /*----------------------------------------------------------------------- * show frame info *-----------------------------------------------------------------------*/ printf("\n[debug] frame info\n"); printf("[debug] image_bytes: %d\n", frame->image_bytes); printf("[debug] size[0]: %d\n", frame->size[0]); printf("[debug] size[1]: %d\n", frame->size[1]); printf("[debug] allocated_image_bytes: %d\n", frame->allocated_image_bytes ); printf("[debug] total_bytes: %d\n", frame->total_bytes ); printf("[debug] color_coding: %d\n", frame->color_coding); printf("[debug] color_filter: %d\n", frame->color_filter); printf("[debug] packet_size: %d\n", frame->packet_size); printf("[debug] packets_per_frame: %d\n", frame->packets_per_frame); printf("[debug] padding_bytes: %d\n", frame->padding_bytes); printf("[debug] timestamp: %d\n", frame->timestamp); printf("[debug] stride: %d\n", frame->stride); printf("[debug] data_depth: %d\n", frame->data_depth); printf("[debug] id: %d\n", frame->id); printf("[debug] frames_behind: %d\n", frame->frames_behind); printf("[debug] image: %u\n", frame->image); /*----------------------------------------------------------------------- * stop data transmission *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera,dc1394_off); dc1394_err_cln_rtn(err,cleanup_and_exit(camera),"could not stop camera?\n"); /*----------------------------------------------------------------------- * save image 'image.pgm' *-----------------------------------------------------------------------*/ imagefile=fopen(image_file_name, "wb"); if( imagefile == null) { perror( "can't create output file"); cleanup_and_exit(camera); } width = 1104; height = 624; fprintf(imagefile,"p6\n%u %u\n65536\n", width, height); int nbytes = fwrite(frame->image, 2, height*width, imagefile); fclose(imagefile); printf("wrote: " image_file_name " (%d image bytes)\n",nbytes*2); /*----------------------------------------------------------------------- * close camera *-----------------------------------------------------------------------*/ dc1394_video_set_transmission(camera, dc1394_off); dc1394_capture_stop(camera); dc1394_camera_free(camera); dc1394_free (d); return 0; }
it compiled when tried execute it. got following following error.
libdc1394 error: format_7 error_flag_1 set: in _dc1394_v130_handshake (format7.c, line 122): invalid image position, size, color coding or iso speed libdc1394 error: format_7 error_flag_1 set: in dc1394_format7_set_roi (format7.c, line 803): handshaking failed after setting color_coding libdc1394 error: format_7 error_flag_1 set: in main (test.c, line 90): not roi
can 1 tell me how can set dc1394_format7_set_roi(parametre) , dc1394_video_set_mode (parameter) stero images.
Comments
Post a Comment