コード例 #1
0
ファイル: camera.cpp プロジェクト: JoshMarino/lims-hsv-system
int update_roi(Fg_Struct *fg, int label, int w, int h, double e, double f, int init)
{
    // setup one ROI, ROI0
	int rc;
	FC_ParameterSet lRoiParameterSet;

    memset(&lRoiParameterSet, 0, sizeof(FC_ParameterSet));
	
	if(setParameterSetRoi(&lRoiParameterSet, 0, w, 0, h) < 0) {
		printf("set roi: %s\n", Fg_getLastErrorDescription(fg));
	}
    
	if(setParameterSetTime(&lRoiParameterSet, e, f) < 0) {
		printf("set time: %s\n", Fg_getLastErrorDescription(fg));
	}

	if(setParameterSetLinlog(&lRoiParameterSet, 0, 0, 0, 0) < 0) {
		printf("set linlog: %s\n", Fg_getLastErrorDescription(fg));
	}

    rc = writeParameterSet(fg, &lRoiParameterSet, 0, label, init, PORT_A);
	if(rc < 0) {
		printf("write params: %s\n", Fg_getLastErrorDescription(fg));
	}

	return rc;
}
コード例 #2
0
ファイル: CameraLink.cpp プロジェクト: Ryuk4/crappy
void *Camera::getBuffer(){
  try{
    cur_pic_nr = Fg_getLastPicNumberBlockingEx(fg, last_pic_nr + 1, camPort, timeout, memHandle);
    if (cur_pic_nr < 0) {
      sprintf(Data,"Fg_getLastPicNumberBlockingEx(%li) failed: %s\n",last_pic_nr+1, Fg_getLastErrorDescription(fg));
//       cout << "timeout: " << timeout << endl;
      stop();
      throw string(Data);
    }else{
      last_pic_nr = cur_pic_nr;
//       timeout=4;
      void *ImgPtr = Fg_getImagePtrEx(fg, last_pic_nr, camPort, memHandle);
      return ImgPtr;
    }
  }catch(string const& error){
    cout <<"ERROR11: " << error << endl;
    sleep(5);
    timeout+= 100;
    cout << "timeouttest: " << timeout << endl;
    last_pic_nr = 0;
    init(m_file);
    startAcquire();
    return getBuffer();
  }
}
コード例 #3
0
ファイル: uca-pco-camera.c プロジェクト: MariaMatveeva/libuca
static gboolean
setup_frame_grabber (UcaPcoCameraPrivate *priv)
{
    guint32 fg_width;
    guint32 fg_height;
    int val;

    priv->fg_port = PORT_A;
    priv->fg = Fg_Init (priv->description->so_file, priv->fg_port);

    if (priv->fg == NULL) {
        g_set_error (&priv->construct_error, UCA_PCO_CAMERA_ERROR, UCA_PCO_CAMERA_ERROR_FG_INIT,
                     "%s", Fg_getLastErrorDescription(priv->fg));
        return FALSE;
    }

    FG_TRY_PARAM (priv->fg, &priv->construct_error, FG_CAMERA_LINK_CAMTYP, &priv->description->cl_type, priv->fg_port);
    FG_TRY_PARAM (priv->fg, &priv->construct_error, FG_FORMAT, &priv->description->cl_format, priv->fg_port);

    fg_width = priv->description->type == CAMERATYPE_PCO_EDGE ? priv->width * 2 : priv->width;
    FG_TRY_PARAM (priv->fg, &priv->construct_error, FG_WIDTH, &fg_width, priv->fg_port);

    fg_height = priv->height;
    FG_TRY_PARAM (priv->fg, &priv->construct_error, FG_HEIGHT, &fg_height, priv->fg_port);

    val = FREE_RUN;
    FG_TRY_PARAM (priv->fg, &priv->construct_error, FG_TRIGGERMODE, &val, priv->fg_port);

    return TRUE;
}
コード例 #4
0
ファイル: CameraLink.cpp プロジェクト: Ryuk4/crappy
int Camera::init(const char* file) {
  int isSlave =0;
  if ((fg = Fg_InitEx("FullAreaGray8", m_boardNr, isSlave)) == NULL) {
    fprintf(stderr, "error in Fg_InitEx: %s\n", Fg_getLastErrorDescription(NULL));
    exit(EXIT_FAILURE);
  }
  m_file = file;
  if(Fg_loadConfig(fg,file)!=FG_OK){
    printf("\nFile config loading failed\n");
    exit(EXIT_FAILURE);
  }
  ComNr=m_boardNr*2;
  serialInit(ComNr);
  
  if(Fg_setParameter(fg,FG_TRIGGERMODE,&TriggerMode,camPort)==FG_OK){
    printf("\nTrig config succeed\n");
  }
  size_t totalBufferSize = m_width * m_height * samplePerPixel * bytePerSample * nbBuffers;
  memHandle = Fg_AllocMemEx(fg, totalBufferSize, nbBuffers);
  if (memHandle == NULL) {
    fprintf(stderr, "error in Fg_AllocMemEx: %s\n", Fg_getLastErrorDescription(fg));
    Fg_FreeGrabber(fg);
    exit(EXIT_FAILURE);
  }
  try{
//     if(setExposure(m_exposure)!=FG_OK){throw 0;}
//     setWidth(m_width);
//     setHeight(m_height);
//     setYoffset(m_yoffset);
//     setXoffset(m_xoffset);
    int bitAlignment = FG_LEFT_ALIGNED;
    CHECK(FG_BITALIGNMENT, "FG_BITALIGNMENT", &bitAlignment);
    CHECK(FG_FRAMESPERSEC, "FG_FRAMESPERSEC",  &m_framespersec);
    CHECK(FG_TIMEOUT, "FG_TIMEOUT", &timeout);
//     startAcquire();
    cout << "test" << endl;
  }catch(string const& error){
    cout << "ERROR: " << error <<endl;
    close();
    init(file);
  }catch(int e){
    close();
    init(file);
  }
  return FG_OK;
}
コード例 #5
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;
}
コード例 #6
0
ファイル: camera.cpp プロジェクト: JoshMarino/lims-hsv-system
int close_cam(Fg_Struct *fg)
{
	if(Fg_setExsync(fg, FG_OFF, PORT_A) < 0) {
		printf("sync off: %s\n", Fg_getLastErrorDescription(fg));
	}

	if(Fg_stopAcquire(fg, PORT_A) != FG_OK) {
		printf("stop acq: %s\n", Fg_getLastErrorDescription(fg));
	}

	if(FastConfigFree(PORT_A) != FG_OK) {
		printf("FC free: %s\n", Fg_getLastErrorDescription(fg));
	}

	if(Fg_FreeGrabber(fg) != FG_OK) {
		printf("free grabber: %s\n", Fg_getLastErrorDescription(fg));
	}

	return FG_OK;
}
コード例 #7
0
ファイル: camera.cpp プロジェクト: JoshMarino/lims-hsv-system
int get_images(Fg_Struct *fg, int num_imgs)
{
	int rc;

	if(Fg_Acquire(fg, PORT_A, GRAB_INFINITE) < 0) {
		printf("acq: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
        close_cam(fg);
		return rc;
	}

	return FG_OK;
}
コード例 #8
0
cv::Mat E2VCameraDirectRead::GetImage()
{
	if (HasBeenInited)
	{
		//acquire one image per subbuffer
		//1.fg
		//2.采集卡口
		//3.采集帧数
		//4.?
		//5.缓存地址
		if ((Fg_AcquireEx(E2VCameraModel::fg, _camPort, 1, ACQ_STANDARD, memHandle)) < 0) {
			fprintf(stderr, "Fg_AcquireEx() failed: %s\n", Fg_getLastErrorDescription(fg));
			errorMessageWait(); 
			return cv::Mat();
		}

		frameindex_t fcount = 0;
		frameindex_t last_pic_nr = 0;
		frameindex_t cur_pic_nr;

		cv::Mat OriginalImage;

		cur_pic_nr = Fg_getLastPicNumberBlockingEx(fg, last_pic_nr + 1, _camPort, 100, memHandle);
		if (cur_pic_nr < 0)
		{
			Fg_stopAcquire(fg, _camPort);
			errorMessageWait(); return cv::Mat();
		}
		unsigned char *bytePtr = (unsigned char*)Fg_getImagePtrEx(fg, cur_pic_nr, 0, memHandle);
		//if (nId != -1)
		//	::DrawBuffer(nId, Fg_getImagePtrEx(fg, lastPicNr, 0, memHandle), (int)lastPicNr, "");

		OriginalImage = cv::Mat(_frameHeight, _width, CV_8UC3, bytePtr).clone();
		if (_colorType == GRAY)
		{
			cv::cvtColor(OriginalImage, OriginalImage, CV_BGR2GRAY);
		}

		fcount++;


		Fg_stopAcquireEx(fg, _camPort, memHandle, 0);
		return OriginalImage;
	}
	else
		return cv::Mat();
}
コード例 #9
0
ファイル: uca-pco-camera.c プロジェクト: MariaMatveeva/libuca
static gboolean
uca_pco_camera_grab(UcaCamera *camera, gpointer data, GError **error)
{
    static const gint MAX_TIMEOUT = 5;

    g_return_val_if_fail (UCA_IS_PCO_CAMERA(camera), FALSE);
    UcaPcoCameraPrivate *priv = UCA_PCO_CAMERA_GET_PRIVATE(camera);

    gboolean is_readout = FALSE;
    g_object_get(G_OBJECT(camera), "is-readout", &is_readout, NULL);

    if (is_readout) {
        if (priv->current_image == priv->num_recorded_images)
            return FALSE;

        /*
         * No joke, the pco firmware allows to read a range of images but
         * implements only reading single images ...
         */
        pco_read_images(priv->pco, priv->active_segment, priv->current_image, priv->current_image);
        priv->current_image++;
    }

    pco_request_image(priv->pco);
    priv->last_frame = Fg_getLastPicNumberBlockingEx(priv->fg, priv->last_frame + 1, priv->fg_port, MAX_TIMEOUT, priv->fg_mem);

    if (priv->last_frame <= 0) {
        g_set_error (error, UCA_PCO_CAMERA_ERROR,
                     UCA_PCO_CAMERA_ERROR_FG_GENERAL,
                     "%s", Fg_getLastErrorDescription(priv->fg));
        return FALSE;
    }

    guint16 *frame = Fg_getImagePtrEx(priv->fg, priv->last_frame, priv->fg_port, priv->fg_mem);

    if (priv->description->type == CAMERATYPE_PCO_EDGE)
        pco_get_reorder_func(priv->pco)((guint16 *) data, frame, priv->frame_width, priv->frame_height);
    else
        memcpy((gchar *) data, (gchar *) frame, priv->frame_width * priv->frame_height * priv->num_bytes);

    return TRUE;
}
コード例 #10
0
ファイル: camera.cpp プロジェクト: JoshMarino/lims-hsv-system
int open_cam(Fg_Struct **gr, int mode, int num_images, int w, int h)
{
	Fg_Struct *fg = NULL;
	FastConfigSequence mFcs;
	int rc;

	fg = Fg_Init(APPLET, PORT_A);
	if(fg == NULL) {
		printf("init: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

	if(Fg_setParameter(fg, FG_TRIGGERMODE, &mode, PORT_A) < 0) {
		printf("mode: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

	rc = FG_CL_DUALTAP_8_BIT;
	if(Fg_setParameter(fg, FG_CAMERA_LINK_CAMTYP, &rc, PORT_A) < 0) {
		printf("dual tap: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

	if(Fg_setExsync(fg, FG_ON, PORT_A) < 0) {
		printf("sync on: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

	// I don't think the next two do anything
    rc = FG_ON;
	if(Fg_setParameter(fg, FG_EXSYNCINVERT, &rc, PORT_A) < 0) {
		printf("sync invert: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

    rc = FG_ON;
	if(Fg_setParameter(fg, FG_EXSYNCPOLARITY, &rc, PORT_A) < 0) {
		printf("sync polarity: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

	if(Fg_AllocMem(fg, w*h*num_images, num_images, PORT_A) == NULL) {
		printf("mem: %s\n", Fg_getLastErrorDescription(fg));
		rc = Fg_getLastErrorNumber(fg);
		close_cam(fg);
		return rc;
	}

	// FastConfig parameters

	if(FastConfigInit(PORT_A) != FG_OK) {
        printf("fc init: %s\n", Fg_getLastErrorDescription(fg));
        rc = Fg_getLastErrorNumber(fg);
        close_cam(fg);
        return rc;
    }

	// only one ROI
	mFcs.mLengthOfSequence = SEQ_LEN;
	mFcs.mRoiPagePointer = new int[SEQ_LEN];
	mFcs.mRoiPagePointer[0]	= 0;

    if(Fg_setParameter(fg, FG_FASTCONFIG_SEQUENCE, &mFcs, PORT_A) != FG_OK) {
        printf("fc seq: %s\n", Fg_getLastErrorDescription(fg));
        rc = Fg_getLastErrorNumber(fg);
        close_cam(fg);
        return rc;
    }

	*gr = fg;
	return FG_OK;
}
コード例 #11
0
int main()
{
	// important variables used in most applications
	int rc;
	Fg_Struct *fg = NULL;
	int img_nr;
	TrackingWindow cur;
	int seq[] = SEQ;

	// following lines are for displaying images only!  See OpenCV doc for more info.
	// they can be left out, if speed is important.
	IplImage *cvDisplay = NULL;

	cvDisplay = cvCreateImageHeader(cvSize(ROI_BOX, ROI_BOX), 
		BITS_PER_PIXEL, NUM_CHANNELS);
	cvNamedWindow(DISPLAY, CV_WINDOW_AUTOSIZE);
	
	// initialize the tracking window (i.e. blob and ROI positions)
	memset(&cur, 0, sizeof(TrackingWindow));
	set_initial_positions(&cur);

	// initialize the camera
	rc = init_cam(&fg, MEMSIZE(cur.roi_w, cur.roi_h), NUM_BUFFERS, CAMLINK);
	if(rc != FG_OK) {
		printf("init: %s\n", Fg_getLastErrorDescription(fg));
		Fg_FreeGrabber(fg);
		return rc;
	}

	// start acquiring images (this function also writes any buffered ROIs to the camera)
	rc = acquire_imgs(fg, (int *) &seq, SEQ_LEN);
	if(rc != FG_OK) {
		printf("init: %s\n", Fg_getLastErrorDescription(fg));
		Fg_FreeGrabber(fg);
		return rc;
	}

	// initialize parameters
	img_nr = 1;

	// start image loop and don't stop until the user presses 'q'
	printf("press 'q' at any time to quit this demo.");
	while(!(_kbhit() && _getch() == 'q')) {
		img_nr = Fg_getLastPicNumberBlocking(fg, img_nr, PORT_A, TIMEOUT);
		cur.img = (unsigned char *) Fg_getImagePtr(fg, img_nr, PORT_A);

		// make sure that camera returned a valid image
		if(cur.img != NULL) {
			// increment to the next desired frame.  This has to be at least
			// +2, because the camera's ROI will not be active until the second
			// frame (see Silicon Software FastConfig doc)
			img_nr += NEXT_IMAGE;

			// process image
			threshold(&cur, THRESHOLD);
			erode(&cur);

			// update ROI position
			position(&cur);

			// at this point position(...) has updated the ROI, but it only stores
			// the updated values internal to the code.  The next step is to flush
			// the ROI to the camera (see position(...) documentation).

			// write ROI position to camera to be updated on frame "img_nr"
			write_roi(fg, cur.roi, img_nr, !DO_INIT);

			// show image on screen
			display_tracking(&cur, cvDisplay);
		}
		else {
			// typically this state only occurs if an invalid ROI has been programmed
			// into the camera (e.g. roi_w == 4).
			printf("img is null: %d\n", img_nr);
			break;
		}
	}

	// free viewer resources
	cvReleaseImageHeader(&cvDisplay);

	// free camera resources
	rc = deinit_cam(fg);
	if(rc != FG_OK) {
		printf("deinit: %s\n", Fg_getLastErrorDescription(fg));
		return rc;
	}

	return FG_OK;
}
コード例 #12
0
ファイル: uca-pco-camera.c プロジェクト: MariaMatveeva/libuca
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);
}