Last active
September 24, 2019 08:59
-
-
Save matwey/7c26c7ee3a4b45c19df8700641857d32 to your computer and use it in GitHub Desktop.
ieee1394 iicd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <dc1394/dc1394.h> | |
| #include <inttypes.h> | |
| int main(int argc, char** argv) { | |
| dc1394_t * d; | |
| dc1394camera_list_t * list; | |
| dc1394error_t err; | |
| dc1394camera_t *camera; | |
| dc1394featureset_t features; | |
| dc1394color_coding_t color_coding; | |
| dc1394video_frame_t* frame; | |
| uint32_t packet_size, left, top, width, height; | |
| FILE* imagefile; | |
| int i = 0; | |
| d = dc1394_new(); | |
| if (!d) | |
| return 1; | |
| err = dc1394_camera_enumerate (d, &list); | |
| printf("Enumerated cameras. %d cameras found\n", list->num); | |
| if (list->num == 0) | |
| return 1; | |
| camera = dc1394_camera_new (d, list->ids[0].guid); | |
| printf("Using first camera %" PRIx64 "\n", list->ids[0].guid); | |
| if (!camera) | |
| return 1; | |
| dc1394_camera_free_list (list); | |
| err = dc1394_camera_reset(camera); | |
| printf("Reset camera: %s\n", dc1394_error_get_string(err)); | |
| err = dc1394_feature_get_all(camera, &features); | |
| if (err != DC1394_SUCCESS) { | |
| printf("Could not get camera feature set\n"); | |
| goto fail_feature_get_all; | |
| } | |
| dc1394_feature_print_all(&features, stdout); | |
| dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400); | |
| dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0); | |
| err = dc1394_format7_set_roi(camera, DC1394_VIDEO_MODE_FORMAT7_0, DC1394_COLOR_CODING_MONO16, DC1394_USE_MAX_AVAIL, 0, 0, DC1394_USE_MAX_AVAIL, DC1394_USE_MAX_AVAIL); | |
| if (err != DC1394_SUCCESS) { | |
| printf("Could not set format 7 roi\n"); | |
| goto fail_format7_set_roi; | |
| } | |
| err = dc1394_format7_get_roi(camera, DC1394_VIDEO_MODE_FORMAT7_0, &color_coding, &packet_size, &left, &top, &width, &height); | |
| if (err != DC1394_SUCCESS) { | |
| printf("Could not get format 7 roi\n"); | |
| goto fail_format7_get_roi; | |
| } | |
| printf("Camera packet size = %u bytes\n", packet_size); | |
| printf("Camera frame geometry = (%u,%u) (%u,%u)\n", left, top, width, height); | |
| printf("Camera color coding = %d\n", color_coding); | |
| err = dc1394_capture_setup(camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT); | |
| if (err != DC1394_SUCCESS) { | |
| printf("Could not set camera capture\n"); | |
| goto fail_capture_setup; | |
| } | |
| err = dc1394_video_set_transmission(camera, DC1394_ON); | |
| if (err != DC1394_SUCCESS) { | |
| printf("Could not start camera iso transmission\n"); | |
| goto fail_video_set_transmission; | |
| } | |
| for (i = 0; i < 100; ++i) { | |
| err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame); | |
| if (err != DC1394_SUCCESS) { | |
| printf("Could not dequeue frame\n"); | |
| goto fail_capture_dequeue; | |
| } | |
| printf("%d %" PRIu64 "\n", i, frame->timestamp); | |
| dc1394_capture_enqueue(camera, frame); | |
| } | |
| dc1394_video_set_transmission(camera,DC1394_OFF); | |
| imagefile = fopen("frame.pgm","wb"); | |
| fprintf(imagefile,"P5\n%u %u\n65535\n", width, height); | |
| fwrite(frame->image, 2, height * width, imagefile); | |
| fclose(imagefile); | |
| dc1394_capture_stop(camera); | |
| dc1394_camera_free(camera); | |
| dc1394_free(d); | |
| return 0; | |
| fail_capture_dequeue: | |
| fail_video_set_transmission: | |
| dc1394_capture_stop(camera); | |
| fail_capture_setup: | |
| fail_format7_get_roi: | |
| fail_format7_set_roi: | |
| fail_feature_get_all: | |
| dc1394_camera_free(camera); | |
| dc1394_free(d); | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment