示例#1
0
String
BaslerCamera::capture(const String& outdir) {
	String outfile;

	// Let the camera acquire one single image ( Acquisiton mode equals
	// SingleFrame! )
	_cam->AcquisitionStart.Execute();

	// Wait for the grabbed image with a timeout of 3 seconds
	if (_streamGrabber->GetWaitObject().Wait(3000)) {
		// Get the grab result from the grabber's result queue
		GrabResult res;
		_streamGrabber->RetrieveResult(res);

		if (res.Succeeded()) {
			// Get the pointer to the image buffer
			const uint8_t *pImageBuffer = (uint8_t *) res.Buffer();

			// Save the buffer as a JPEG-compressed image in a unique filename inside outdir and return its name
			outfile =  saveJpegImage(outdir, pImageBuffer, res.GetSizeX(), res.GetSizeY());

			// Prepare for next frame
			_streamGrabber->QueueBuffer(res.Handle(), res.Context());
		}
		else
			throw RuntimeError("An error occurred when trying to capture the image from camera " + _name);
	}
	else {
		// Get the pending buffer back (You are not allowed to deregister
		// buffers when they are still queued)
		_streamGrabber->CancelGrab();

		// Get all buffers back
		for (GrabResult r; _streamGrabber->RetrieveResult(r););

		throw RuntimeError("Acquisition from camera " + this->getName() + " timed out!");
	}

	return outfile;
}