예제 #1
0
int MicroDisplayControler::FreeRunning(MicroDisplayInit& mdi, BufferStorage& s)
{
	//采集mdi.MaxPics行图像到缓存
	if (MicroDisplayControler::StartGrabbing(mdi) < 0)
	{
		MD_ErrorMessageWait(mdi.fg);
		return -1;
	}
	frameindex_t lastPicNr = 0;
	cv::Mat OriginalImage;
	do{
		lastPicNr = Fg_getLastPicNumberBlockingEx(mdi.fg, lastPicNr + 1, mdi.nCamPort, 100, mdi.pMem0);
		if (lastPicNr < 0){
			int status = 0;
			MD_ErrorMessageWait(mdi.fg);
			Fg_stopAcquireEx(mdi.fg, mdi.nCamPort, mdi.pMem0, 0);
			Fg_FreeMemEx(mdi.fg, mdi.pMem0);
			Fg_FreeGrabber(mdi.fg);
			CloseDisplay(mdi.nId);
			return -1;
		}
		unsigned char *bytePtr = (unsigned char*)Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0);
		if (mdi.nId != -1)
			::DrawBuffer(mdi.nId, Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0), (int)lastPicNr, "");
		if (mdi.colorType == mdi.GRAY)
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8U, bytePtr);
		else
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8UC3, bytePtr);
	} while (!s.AddFrame(OriginalImage));
	MicroDisplayControler::EndGrabbing(mdi);
	//功能主循环END
	return 0;
}
예제 #2
0
static void
uca_pco_camera_finalize(GObject *object)
{
    UcaPcoCameraPrivate *priv = UCA_PCO_CAMERA_GET_PRIVATE(object);

    if (priv->horizontal_binnings)
        g_value_array_free (priv->horizontal_binnings);

    if (priv->vertical_binnings)
        g_value_array_free (priv->vertical_binnings);

    if (priv->pixelrates)
        g_value_array_free (priv->pixelrates);

    if (priv->fg) {
        if (priv->fg_mem)
            Fg_FreeMemEx(priv->fg, priv->fg_mem);

        Fg_FreeGrabber (priv->fg);
    }

    if (priv->pco)
        pco_destroy (priv->pco);

    g_free (priv->grab_buffer);
    g_clear_error (&priv->construct_error);

    G_OBJECT_CLASS (uca_pco_camera_parent_class)->finalize (object);
}
예제 #3
0
파일: CameraLink.cpp 프로젝트: Ryuk4/crappy
int Camera::startAcquire(){
  if ((Fg_AcquireEx(fg, camPort, nrOfPicturesToGrab, ACQ_STANDARD, memHandle)) < 0) {
    fprintf(stderr, "Fg_AcquireEx() failed: %s\n", Fg_getLastErrorDescription(fg));
    Fg_FreeMemEx(fg, memHandle);
    Fg_FreeGrabber(fg);
    return FG_ERROR;
  }
  return FG_OK;
}
예제 #4
0
int MicroDisplayControler::FreeRunningFocusing(MicroDisplayInit& mdi)
{
	std::cout << "开始对焦,按1放大,按2缩小,按3退出。\r\n";
	//采集mdi.MaxPics行图像到缓存
	if (MicroDisplayControler::StartGrabbing(mdi) < 0)
	{
		MD_ErrorMessageWait(mdi.fg);
		return -1;
	}
	cv::Mat OriginalImage;
	int resize = mdi.width;
	frameindex_t lastPicNr = 0;
	cv::namedWindow("SHOW", CV_WINDOW_AUTOSIZE);
	int pos = 0;
	int realPos = 0;
	const int maxpos = 80;
	cv::createTrackbar("OFF SET / %", "SHOW", &pos, maxpos);
	do{
		lastPicNr = Fg_getLastPicNumberBlockingEx(mdi.fg, lastPicNr + 1, mdi.nCamPort, 100, mdi.pMem0);
		if (lastPicNr < 0){
			int status = 0;
			MD_ErrorMessageWait(mdi.fg);
			Fg_stopAcquireEx(mdi.fg, mdi.nCamPort, mdi.pMem0, 0);
			Fg_FreeMemEx(mdi.fg, mdi.pMem0);
			Fg_FreeGrabber(mdi.fg);
			CloseDisplay(mdi.nId);

			return 0;
		}
		unsigned char *bytePtr = (unsigned char*)Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0);
		//if (mdi.nId != -1)
		//	::DrawBuffer(mdi.nId, Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0), (int)lastPicNr, "");
		if (mdi.colorType == mdi.GRAY)
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8U, bytePtr);
		else
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8UC3, bytePtr);
		if (resize != mdi.width)
			cv::resize(OriginalImage, OriginalImage, cv::Size(resize, mdi.height));
		realPos = resize / 100 * pos;
		cv::Mat ROI = OriginalImage(cv::Rect(realPos, 0, resize - realPos, mdi.height));
		cv::imshow("SHOW", ROI);
		char t = cv::waitKey(20);
		if (t == '3')
			break;
		if (t == '2' && resize > 800)
			resize /= 2;
		if (t == '1' && resize <  mdi.width * 3)
			resize *= 2;

	} while (true);
	MicroDisplayControler::EndGrabbing(mdi);
	cv::destroyAllWindows();
	//功能主循环END
	return 0;
}
예제 #5
0
파일: CameraLink.cpp 프로젝트: Ryuk4/crappy
void Camera::close(){
  Fg_stopAcquire(fg,camPort);
  Fg_FreeMemEx(fg, memHandle);
  Fg_FreeGrabber(fg);
  free(serialRefPtr);
}
예제 #6
0
static void
uca_pco_camera_start_recording (UcaCamera *camera, GError **error)
{
    g_return_if_fail(UCA_IS_PCO_CAMERA(camera));
    guint err = PCO_NOERROR;

    UcaPcoCameraPrivate *priv = UCA_PCO_CAMERA_GET_PRIVATE(camera);
    guint16 binned_width, binned_height;
    gboolean use_extended = FALSE;
    gboolean transfer_async = FALSE;

    g_object_get (camera, "sensor-extended", &use_extended, NULL);

    if (use_extended) {
        binned_width = priv->width_ex;
        binned_height = priv->height_ex;
    }
    else {
        binned_width = priv->width;
        binned_height = priv->height;
    }

    binned_width /= priv->binning_h;
    binned_height /= priv->binning_v;

    if ((priv->roi_x + priv->roi_width > binned_width) || (priv->roi_y + priv->roi_height > binned_height)) {
        g_set_error(error, UCA_PCO_CAMERA_ERROR, UCA_PCO_CAMERA_ERROR_UNSUPPORTED,
                "ROI of size %ix%i @ (%i, %i) is outside of (binned) sensor size %ix%i\n",
                priv->roi_width, priv->roi_height, priv->roi_x, priv->roi_y, binned_width, binned_height);
        return;
    }

    /*
     * All parameters are valid. Now, set them on the camera.
     */
    guint16 roi[4] = { priv->roi_x + 1, priv->roi_y + 1, priv->roi_x + priv->roi_width, priv->roi_y + priv->roi_height };

    if (pco_set_roi(priv->pco, roi) != PCO_NOERROR) {
        g_set_error(error, UCA_PCO_CAMERA_ERROR, UCA_PCO_CAMERA_ERROR_LIBPCO_GENERAL,
                "Could not set ROI via pco_set_roi()");
        return;
    }

    g_object_get(G_OBJECT(camera), "transfer-asynchronously", &transfer_async, NULL);

    /*
     * FIXME: We cannot set the binning here as this breaks communication with
     * the camera. Setting the binning works _before_ initializing the frame
     * grabber though. However, it is rather inconvenient to initialize and
     * de-initialize the frame grabber for each recording sequence.
     */

    /* if (pco_set_binning(priv->pco, priv->binning_h, priv->binning_v) != PCO_NOERROR) */
    /*     g_warning("Cannot set binning\n"); */

    if (priv->frame_width != priv->roi_width || priv->frame_height != priv->roi_height || priv->fg_mem == NULL) {
        guint fg_width = priv->description->type == CAMERATYPE_PCO_EDGE ? 2 * priv->roi_width : priv->roi_width;

        priv->frame_width = priv->roi_width;
        priv->frame_height = priv->roi_height;
        priv->num_bytes = 2;

        Fg_setParameter(priv->fg, FG_WIDTH, &fg_width, priv->fg_port);
        Fg_setParameter(priv->fg, FG_HEIGHT, &priv->frame_height, priv->fg_port);

        if (priv->fg_mem)
            Fg_FreeMemEx(priv->fg, priv->fg_mem);

        const guint num_buffers = 2;
        priv->fg_mem = Fg_AllocMemEx(priv->fg,
                num_buffers * priv->frame_width * priv->frame_height * sizeof(uint16_t), num_buffers);

        if (priv->fg_mem == NULL) {
            g_set_error(error, UCA_PCO_CAMERA_ERROR, UCA_PCO_CAMERA_ERROR_FG_INIT,
                    "%s", Fg_getLastErrorDescription(priv->fg));
            g_object_unref(camera);
            return;
        }
    }

    if (transfer_async)
        setup_fg_callback(camera);

    if (is_type (priv, CAMERATYPE_PCO_DIMAX_STD) || is_type (priv, CAMERATYPE_PCO4000))
        pco_clear_active_segment(priv->pco);

    /*
     * Set the storage mode to FIFO buffer otherwise pco.4000 skips
     * frames that it is not able to send in time.
     */
    if (is_type (priv, CAMERATYPE_PCO4000))
        pco_set_storage_mode (priv->pco, STORAGE_MODE_FIFO_BUFFER);

    priv->last_frame = 0;

    err = pco_arm_camera(priv->pco);
    HANDLE_PCO_ERROR(err);

    err = pco_start_recording(priv->pco);
    HANDLE_PCO_ERROR(err);

    err = Fg_AcquireEx(priv->fg, priv->fg_port, GRAB_INFINITE, ACQ_STANDARD, priv->fg_mem);
    FG_SET_ERROR(err, priv->fg, UCA_PCO_CAMERA_ERROR_FG_ACQUISITION);
}
예제 #7
0
void MicroDisplayInit::Release(MicroDisplayInit& mdi)
{
	Fg_FreeMemEx(mdi.fg, mdi.pMem0);
	Fg_FreeGrabber(mdi.fg);
	CloseDisplay(mdi.nId);
}