Ejemplo n.º 1
0
int capture_single(capture_t *cap, const int index, capture_frame_t *frame)
{
  dc1394camera_t *cam = cap->cameras[index];
  dc1394error_t err;
  dc1394video_frame_t *vframe = NULL;
  uint32_t frames_behind = 0;

  if (cap->prefer_one_shot && cam->one_shot_capable == DC1394_TRUE) {
    err = dc1394_video_set_one_shot(cam, DC1394_ON);
    DC1394_WRN(err, "could not set one shot mode.");
    if (err != DC1394_SUCCESS) {
      return CAPTURE_ERROR;
    }
  }

  err = dc1394_capture_dequeue(cam, DC1394_CAPTURE_POLICY_WAIT, &vframe);
  DC1394_WRN(err, "could not dequeue frame.");
  if (err != DC1394_SUCCESS) {
    return CAPTURE_ERROR;
  }
  frames_behind = vframe->frames_behind;

  /* copy the image to frame->raw_data */
  s_copy_frame(vframe, frame);

  err = dc1394_capture_enqueue(cam, vframe);
  DC1394_WRN(err, "could not enqueue frame.");
  if (err != DC1394_SUCCESS) {
    return CAPTURE_ERROR;
  }

  /* drop behind frames if drop_frame is enable */
  if (cap->drop_frames) {
    while (frames_behind-- > 0) {
      err = dc1394_capture_dequeue(cam, DC1394_CAPTURE_POLICY_WAIT, &vframe);
      DC1394_WRN(err, "could not dequeue frame.");
      if (err != DC1394_SUCCESS) {
        return CAPTURE_ERROR;
      }
      
      err = dc1394_capture_enqueue(cam, vframe);
      DC1394_WRN(err, "could not enqueue frame.");
      if (err != DC1394_SUCCESS) {
        return CAPTURE_ERROR;
      }
    }
  }

  return CAPTURE_SUCCESS;
}
Ejemplo n.º 2
0
void ofxLibdc::grabStill(ofImage& img) {
	setTransmit(false);
	flushBuffer();
	dc1394_video_set_one_shot(camera, DC1394_ON);
	// if possible, the following should be replaced with a call to grabFrame
	dc1394video_frame_t *frame;
	dc1394_capture_dequeue(camera, capturePolicy, &frame);
	img.allocate(width, height, imageType);
	if(imageType == OF_IMAGE_GRAYSCALE) {
		memcpy(img.getPixels(), frame->image, width * height);
	} else if(imageType == OF_IMAGE_COLOR) {
	}
	dc1394_capture_enqueue(camera, frame);
}
Ejemplo n.º 3
0
CameraFrame CameraIIDC::getFrame(){

    CameraFrame frame;

    if (!capturing) {
        cerr << "ERROR: Not capturing on camera. Call startCapture() before lockFrame()." << endl;
        return frame;
    }

    dc1394error_t err;
    
    if(triggerMode == triggerModeSoftware){

        if (cam->one_shot_capable != DC1394_TRUE){
            cerr << "ERROR: Camera is not one_shot_capable." << endl;
            return frame;
        }

        dc1394error_t err;

        // Flush the ring buffer
        flushBuffer();

        // One-shot trigger
        err == dc1394_video_set_one_shot(cam, DC1394_ON);

    }

    // Get frame from ring buffer:
    err = dc1394_capture_dequeue(cam, DC1394_CAPTURE_POLICY_WAIT, &currentFrame);
    if (err!=DC1394_SUCCESS){
        cerr << "ERROR: Could not capture a frame." << endl;
        return frame;
    }

    // Return the frame to the ring buffer:
    dc1394_capture_enqueue(cam, currentFrame);
    currentFrame = NULL;

    // Copy frame address and properties
    frame.memory = currentFrame->image;
    frame.width = currentFrame->size[0];
    frame.height = currentFrame->size[1];
    frame.sizeBytes = currentFrame->image_bytes;

    return frame;
}
Ejemplo n.º 4
0
void ofxLibdc::getOneShot(ofImage& img) {
	setTransmit(false);
	flush();
	dc1394_video_set_one_shot(camera, DC1394_ON);
	dc1394video_frame_t *frame;
	dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
	img.allocate(width, height, imageType);
	if(imageType == OF_IMAGE_GRAYSCALE) {
		memcpy(img.getPixels(), frame->image, width * height);
	} else if(imageType == OF_IMAGE_COLOR) {
		// this shouldn't be reallocated every frame!
		dc1394video_frame_t* rgbFrame = (dc1394video_frame_t*) calloc(1, sizeof(dc1394video_frame_t));
    rgbFrame->color_coding = DC1394_COLOR_CODING_RGB8;
    dc1394_convert_frames(frame, rgbFrame);
		memcpy(img.getPixels(), rgbFrame->image, 3 * width * height);
		free(rgbFrame);
	}
	img.setFromPixels(frame->image, width, height, imageType);
	dc1394_capture_enqueue(camera, frame);
}
Ejemplo n.º 5
0
int capture_multi(capture_t *cap, capture_frame_t *frames)
{
  int i;
  dc1394error_t err;
  dc1394video_frame_t **vframes = NULL;
  uint32_t frames_behind = 0;

  vframes = (dc1394video_frame_t **)malloc(sizeof(dc1394video_frame_t *) * cap->num_active);
  if (vframes == NULL) {
    return CAPTURE_ERROR;
  }

  for (i = 0; i < cap->num_active; ++i) {
    if (cap->prefer_one_shot && cap->cameras[i]->one_shot_capable) {
      err = dc1394_video_set_one_shot(cap->cameras[i], DC1394_ON);
      DC1394_WRN(err, "could not set one shot mode.");
      if (err != DC1394_SUCCESS) {
        return CAPTURE_ERROR;
      }
    }
  }

  for (i = 0; i < cap->num_active; ++i) {
    err = dc1394_capture_dequeue(cap->cameras[i], DC1394_CAPTURE_POLICY_WAIT, &vframes[i]);
    DC1394_WRN(err, "could not dequeue frame.");
    if (err != DC1394_SUCCESS) {
      free(vframes);
      return CAPTURE_ERROR;
    }
  }

  /* find the minimum number of behind frames */
  frames_behind = vframes[0]->frames_behind;
  for (i = 1; i < cap->num_active; ++i) {
    if (frames_behind > vframes[i]->frames_behind) {
      frames_behind = vframes[i]->frames_behind;
    }
  }

  /* copy the image to frame->raw_data */
  for (i = 0; i < cap->num_active; ++i) {
    s_copy_frame(vframes[i], &frames[i]);
  }

  for (i = 0; i < cap->num_active; ++i) {
    err = dc1394_capture_enqueue(cap->cameras[i], vframes[i]);
    DC1394_WRN(err, "could not enqueue frame.");
    if (err != DC1394_SUCCESS) {
      free(vframes);
      return CAPTURE_ERROR;
    }
  }

  /* drop behind frames if drop_frame is enable */
  if (cap->drop_frames != 0) {
    while (frames_behind-- > 0) {
      for (i = 0; i < cap->num_active; ++i) {
        err = dc1394_capture_dequeue(cap->cameras[i], DC1394_CAPTURE_POLICY_WAIT, &vframes[i]);
        DC1394_WRN(err, "could not dequeue frame.");
        if (err != DC1394_SUCCESS) {
          free(vframes);
          return CAPTURE_ERROR;
        }
      }
      
      for (i = 0; i < cap->num_active; ++i) {
        err = dc1394_capture_enqueue(cap->cameras[i], vframes[i]);
        DC1394_WRN(err, "could not enqueue frame.");    
        if (err != DC1394_SUCCESS) {
          free(vframes);
          return CAPTURE_ERROR;
        }
      }
    }
  }

  free(vframes);

  return CAPTURE_SUCCESS;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) 
{
  // assumes your camera can output 640x480 with 8-bit monochrome
  video_mode = DC1394_VIDEO_MODE_640x480_MONO8;

  d = dc1394_new();
  if (!d)
    return 1;
  err=dc1394_camera_enumerate (d, &list);
  DC1394_ERR_RTN(err,"Failed to enumerate cameras");

  if (list->num == 0) {
    dc1394_log_error("No cameras found");
    return 1;
  }

  // use two counters so tht cameras array does not contain gaps in the case of errors
  j = 0;
  for (i = 0; i < list->num; i++) {
    if (j >= MAX_CAMERAS)
      break;
    cameras[j] = dc1394_camera_new (d, list->ids[i].guid);
    if (!cameras[j]) {
      dc1394_log_warning("Failed to initialize camera with guid %llx", list->ids[i].guid);
      continue;
    }
    j++;
  }
  numCameras = j;
  dc1394_camera_free_list (list);

  if (numCameras == 0) {
    dc1394_log_error("No cameras found");
    exit (1);
  }

  // setup cameras for capture
  for (i = 0; i < numCameras; i++) {
    err=dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_800);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set ISO speed");
    
    err=dc1394_video_set_mode(cameras[i], video_mode);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set video mode");
    
    err=dc1394_capture_setup(cameras[i],NUM_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera");

    err=dc1394_get_image_size_from_video_mode(cameras[i], video_mode, &video_mode_width, &video_mode_height);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not query video mode width and height");

    err=dc1394_video_set_one_shot(cameras[i], DC1394_ON);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not use one shot mode");
  }

    fflush(stdout);
    if (numCameras < 1) {
        perror("no cameras found :(\n");
        cleanup();
        exit(-1);
    }

    for (i = 0; i < numCameras; i++) {
      if (dc1394_capture_dequeue(cameras[i], DC1394_CAPTURE_POLICY_WAIT, &frames[i])!=DC1394_SUCCESS)
	dc1394_log_error("Failed to capture from camera %d", i);

      // save image as '[GUID].pgm'
      char filename[256];
      sprintf(filename, "%" PRIu64 "%s",list->ids[i].guid,IMAGE_FILE_EXTENSION);
      imagefile=fopen(filename, "w");

      if( imagefile == NULL) {
	  dc1394_log_error("Can't create %s", filename);
	}
  
      // adding the pgm file header
      fprintf(imagefile,"P5\n%u %u 255\n", video_mode_width, video_mode_height);

      // writing to the file
      fwrite((const char *)frames[i]->image, 1, \
	     video_mode_width * video_mode_height, imagefile);
      fclose(imagefile);                                    
    }

  // exit cleanly
  cleanup();
  return(0);
}