/** * Write to registers in the MT9V022 chip. * This can be done by programming the address in 0x1A00 and writing to 0x1A04. */ dc1394error_t FFMVCCD::writeMicronReg(unsigned int offset, unsigned int val) { dc1394error_t err; err = dc1394_set_control_register(dcam, 0x1A00, offset); if (err != DC1394_SUCCESS) { return err; } err = dc1394_set_control_register(dcam, 0x1A04, val); if (err != DC1394_SUCCESS) { return err; } return DC1394_SUCCESS; }
//============================================================================= // setEndian() // Set the endian-ness of 16-bit data coming from the camera. // // This is a PGR camera specific register // For more information check the PGR IEEE-1394 Digital Camera Register // Reference // dc1394error_t setEndian( dc1394camera_t* camera, bool bBigEndian ) { uint32_t value; dc1394error_t err; if ( bBigEndian ) { // use 16-bit modes in big endian (default 1394) format value = 0x80000001; } else { // use 16-bit modes in little endian (pgr default) format value = 0x80000000; } err = dc1394_set_control_register( camera, IMAGE_DATA_FORMAT_REGISTER, value ); return err; }
bool CvCaptureCAM_DC1394_v2_CPP::startCapture() { int i; int code = 0; if (!dcCam) return false; if (isoSpeed > 0) { code = dc1394_video_set_iso_speed(dcCam, isoSpeed <= 100 ? DC1394_ISO_SPEED_100 : isoSpeed <= 200 ? DC1394_ISO_SPEED_200 : isoSpeed <= 400 ? DC1394_ISO_SPEED_400 : isoSpeed <= 800 ? DC1394_ISO_SPEED_800 : isoSpeed == 1600 ? DC1394_ISO_SPEED_1600 : DC1394_ISO_SPEED_3200); } // should a specific mode be used if (userMode >= 0) { dc1394video_mode_t wantedMode; dc1394video_modes_t videoModes; dc1394_video_get_supported_modes(dcCam, &videoModes); //set mode from number, for example the second supported mode, i.e userMode = 1 if (userMode < (int)videoModes.num) { wantedMode = videoModes.modes[userMode]; } //set modes directly from DC134 constants (from dc1394video_mode_t) else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX )) { //search for wanted mode, to check if camera supports it int j = 0; while ((j< (int)videoModes.num) && videoModes.modes[j]!=userMode) { j++; } if ((int)videoModes.modes[j]==userMode) { wantedMode = videoModes.modes[j]; } else { userMode = -1; // wanted mode not supported, search for best mode } } else { userMode = -1; // wanted mode not supported, search for best mode } //if userMode is available: set it and update size if (userMode != -1) { code = dc1394_video_set_mode(dcCam, wantedMode); uint32_t width, height; dc1394_get_image_size_from_video_mode(dcCam, wantedMode, &width, &height); frameWidth = (int)width; frameHeight = (int)height; } } if (userMode == -1 && (frameWidth > 0 || frameHeight > 0)) { dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1; dc1394video_modes_t videoModes; dc1394_video_get_supported_modes(dcCam, &videoModes); for (i = 0; i < (int)videoModes.num; i++) { dc1394video_mode_t mode = videoModes.modes[i]; if (mode >= DC1394_VIDEO_MODE_FORMAT7_MIN && mode <= DC1394_VIDEO_MODE_FORMAT7_MAX) continue; int pref = -1; dc1394color_coding_t colorCoding; dc1394_get_color_coding_from_video_mode(dcCam, mode, &colorCoding); uint32_t width, height; dc1394_get_image_size_from_video_mode(dcCam, mode, &width, &height); if ((int)width == frameWidth || (int)height == frameHeight) { if (colorCoding == DC1394_COLOR_CODING_RGB8 || colorCoding == DC1394_COLOR_CODING_RAW8) { bestMode = mode; break; } if (colorCoding == DC1394_COLOR_CODING_YUV411 || colorCoding == DC1394_COLOR_CODING_YUV422 || (colorCoding == DC1394_COLOR_CODING_YUV444 && pref < 1)) { bestMode = mode; pref = 1; break; } if (colorCoding == DC1394_COLOR_CODING_MONO8) { bestMode = mode; pref = 0; } } } if ((int)bestMode >= 0) code = dc1394_video_set_mode(dcCam, bestMode); } if (fps > 0) { dc1394video_mode_t mode; dc1394framerates_t framerates; double minDiff = DBL_MAX; dc1394framerate_t bestFps = (dc1394framerate_t) - 1; dc1394_video_get_mode(dcCam, &mode); dc1394_video_get_supported_framerates(dcCam, mode, &framerates); for (i = 0; i < (int)framerates.num; i++) { dc1394framerate_t ifps = framerates.framerates[i]; double fps1 = (1 << (ifps - DC1394_FRAMERATE_1_875)) * 1.875; double diff = fabs(fps1 - fps); if (diff < minDiff) { minDiff = diff; bestFps = ifps; } } if ((int)bestFps >= 0) code = dc1394_video_set_framerate(dcCam, bestFps); } if (cameraId == VIDERE) { bayerFilter = DC1394_COLOR_FILTER_GBRG; nimages = 2; uint32_t value = 0; dc1394_get_control_register(dcCam, 0x50c, &value); colorStereo = (value & 0x80000000) != 0; } code = dc1394_capture_setup(dcCam, nDMABufs, DC1394_CAPTURE_FLAGS_DEFAULT); if (code >= 0) { FD_SET(dc1394_capture_get_fileno(dcCam), &dc1394.camFds); dc1394_video_set_transmission(dcCam, DC1394_ON); if (cameraId == VIDERE) { enum { PROC_MODE_OFF, PROC_MODE_NONE, PROC_MODE_TEST, PROC_MODE_RECTIFIED, PROC_MODE_DISPARITY, PROC_MODE_DISPARITY_RAW }; int procMode = PROC_MODE_RECTIFIED; usleep(100000); uint32_t qval1 = 0x08000000 | (0x90 << 16) | ((procMode & 0x7) << 16); uint32_t qval2 = 0x08000000 | (0x9C << 16); dc1394_set_control_register(dcCam, 0xFF000, qval1); dc1394_set_control_register(dcCam, 0xFF000, qval2); } started = true; } return code >= 0; }
/************************************************************************************** ** Client is asking us to establish connection to the device ***************************************************************************************/ bool FFMVCCD::Connect() { dc1394camera_list_t *list; dc1394error_t err; bool supported; bool settings_valid; uint32_t val; dc1394format7mode_t fm7; dc1394feature_info_t feature; float min, max; dc1394 = dc1394_new(); if (!dc1394) { return false; } err = dc1394_camera_enumerate(dc1394, &list); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not find DC1394 cameras!"); return false; } if (!list->num) { IDMessage(getDeviceName(), "No DC1394 cameras found!"); return false; } dcam = dc1394_camera_new(dc1394, list->ids[0].guid); if (!dcam) { IDMessage(getDeviceName(), "Unable to connect to camera!"); return false; } /* Reset camera */ err = dc1394_camera_reset(dcam); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to reset camera!"); return false; } /* Set mode */ err = dc1394_video_set_mode(dcam, DC1394_VIDEO_MODE_640x480_MONO16); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to connect to set videomode!"); return false; } /* Disable Auto exposure control */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_EXPOSURE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable auto exposure control"); return false; } /* Set frame rate to the lowest possible */ err = dc1394_video_set_framerate(dcam, DC1394_FRAMERATE_7_5); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to connect to set framerate!"); return false; } /* Turn frame rate control off to enable extended exposure (subs of 512ms) */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_FRAME_RATE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable framerate!"); return false; } /* Get the longest possible exposure length */ err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable manual shutter control."); } err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_SHUTTER, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable absolute shutter control."); } err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_SHUTTER, &min, &max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not get max shutter length"); } else { max_exposure = max; } /* Set gain to max. By setting the register directly, we can achieve a * gain of 24 dB...compared to a gain of 12 dB which is reported as the * max */ err = dc1394_set_control_register(dcam, 0x820, 0x40); //err = dc1394_set_control_register(dcam, 0x820, 0x7f); if (err != DC1394_SUCCESS) { return err; } #if 0 /* Set absolute gain to max */ err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_GAIN, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable ansolute gain control."); } err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_GAIN, &min, &max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not get max gain value"); } else { err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAIN, max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set max gain value"); } } #endif /* Set brightness */ err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable manual brightness control."); } err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable ansolute brightness control."); } err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_BRIGHTNESS, 1); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set max brightness value"); } /* Turn gamma control off */ err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAMMA, 1); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set gamma value"); } err = dc1394_feature_set_power(dcam, DC1394_FEATURE_GAMMA, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable gamma!"); return false; } /* Turn off white balance */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_WHITE_BALANCE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable white balance!"); return false; } err=dc1394_capture_setup(dcam,10, DC1394_CAPTURE_FLAGS_DEFAULT); return true; }
bool CvCaptureCAM_DC1394_v2_CPP::startCapture() { int i; int code = 0; if (!dcCam) return false; if (isoSpeed > 0) { code = dc1394_video_set_iso_speed(dcCam, isoSpeed <= 100 ? DC1394_ISO_SPEED_100 : isoSpeed <= 200 ? DC1394_ISO_SPEED_200 : isoSpeed <= 400 ? DC1394_ISO_SPEED_400 : isoSpeed <= 800 ? DC1394_ISO_SPEED_800 : isoSpeed == 1600 ? DC1394_ISO_SPEED_1600 : DC1394_ISO_SPEED_3200); } if (frameWidth > 0 || frameHeight > 0) { dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1; dc1394video_modes_t videoModes; dc1394_video_get_supported_modes(dcCam, &videoModes); for (i = 0; i < (int)videoModes.num; i++) { dc1394video_mode_t mode = videoModes.modes[i]; if (mode >= DC1394_VIDEO_MODE_FORMAT7_MIN && mode <= DC1394_VIDEO_MODE_FORMAT7_MAX) continue; int pref = -1; dc1394color_coding_t colorCoding; dc1394_get_color_coding_from_video_mode(dcCam, mode, &colorCoding); uint32_t width, height; dc1394_get_image_size_from_video_mode(dcCam, mode, &width, &height); if ((int)width == frameWidth || (int)height == frameHeight) { if (colorCoding == DC1394_COLOR_CODING_RGB8 || colorCoding == DC1394_COLOR_CODING_RGB16 || colorCoding == DC1394_COLOR_CODING_RAW8 || colorCoding == DC1394_COLOR_CODING_RAW16) { bestMode = mode; break; } if (colorCoding == DC1394_COLOR_CODING_YUV411 || colorCoding == DC1394_COLOR_CODING_YUV422 || (colorCoding == DC1394_COLOR_CODING_YUV444 && pref < 1)) { bestMode = mode; pref = 1; } if (colorCoding == DC1394_COLOR_CODING_MONO8 || (colorCoding == DC1394_COLOR_CODING_MONO16 && pref < 0)) { bestMode = mode; pref = 0; } } } if ((int)bestMode >= 0) code = dc1394_video_set_mode(dcCam, bestMode); } if (fps > 0) { dc1394video_mode_t mode; dc1394framerates_t framerates; double minDiff = DBL_MAX; dc1394framerate_t bestFps = (dc1394framerate_t) - 1; dc1394_video_get_mode(dcCam, &mode); dc1394_video_get_supported_framerates(dcCam, mode, &framerates); for (i = 0; i < (int)framerates.num; i++) { dc1394framerate_t ifps = framerates.framerates[i]; double fps1 = (1 << (ifps - DC1394_FRAMERATE_1_875)) * 1.875; double diff = fabs(fps1 - fps); if (diff < minDiff) { minDiff = diff; bestFps = ifps; } } if ((int)bestFps >= 0) code = dc1394_video_set_framerate(dcCam, bestFps); } if (cameraId == VIDERE) { bayerFilter = DC1394_COLOR_FILTER_GBRG; nimages = 2; uint32_t value = 0; dc1394_get_control_register(dcCam, 0x50c, &value); colorStereo = (value & 0x80000000) != 0; } code = dc1394_capture_setup(dcCam, nDMABufs, DC1394_CAPTURE_FLAGS_DEFAULT); if (code >= 0) { FD_SET(dc1394_capture_get_fileno(dcCam), &dc1394.camFds); dc1394_video_set_transmission(dcCam, DC1394_ON); if (cameraId == VIDERE) { enum { PROC_MODE_OFF, PROC_MODE_NONE, PROC_MODE_TEST, PROC_MODE_RECTIFIED, PROC_MODE_DISPARITY, PROC_MODE_DISPARITY_RAW }; int procMode = PROC_MODE_RECTIFIED; usleep(100000); uint32_t qval1 = 0x08000000 | (0x90 << 16) | ((procMode & 0x7) << 16); uint32_t qval2 = 0x08000000 | (0x9C << 16); dc1394_set_control_register(dcCam, 0xFF000, qval1); dc1394_set_control_register(dcCam, 0xFF000, qval2); } started = true; } return code >= 0; }