25 #include <bias_config.h>
26 #include "VideoSource_Base.hh"
27 #include <Base/Image/ImageIO.hh>
28 #include <Base/Image/ImageConvert.hh>
30 #include <Image/VideoStream.hh>
31 #include <Image/Camera.hh>
34 #include <Base/Common/BIASpragma.hh>
37 # include <sys/types.h>
38 # include <sys/stat.h>
122 BIASERR(
"VideoSource::InitImage() should be called with uninitialized image");
131 BIASERR(
"invalid storage type");
146 BIASERR(
"VideoSource::PreGrab() : Object not completely initialized");
151 BIASERR(
"VideoSource::PreGrab() : Object already active");
169 BIASERR(
"VideoSource_Base::OpenDevice() should not be called directly");
175 BIASERR(
"VideoSource_Base::OpenDevice(int device) should not be called directly");
181 BIASERR(
"VideoSource_Base::OpenDevice((const char *filename) should not be called directly");
187 BIASERR(
"VideoSource_Base::OpenDevice(string Prefix, string Postfix, int DigitCount, int PictureCount) should not be called directly");
193 BIASERR(
"VideoSource_Base::OpenDevice(vector<string> FileNames) should not be called directly");
199 BIASERR(
"VideoSource_Base::GetAllDevices(std::vector<std::string> &devices) should not be called directly");
205 BIASERR(
"VideoSource_Base::GetCapabilities() should not be called directly");
211 BIASERR(
"VideoSource_Base::GetCapabilities() should not be called directly");
218 BIASERR(
"VideoSource_Base::CloseDevice() should not be called directly");
224 BIASERR(
"VideoSource_Base::GrabSingle() should not be called, please overload");
231 BIASERR(
"VideoSource_Base::GrabSingle() should not be called, please overload");
235 #ifdef BUILD_IMAGE_USHORT
238 BIASERR(
"VideoSource::GrabSingle() should not be called, please overload");
243 #ifdef BUILD_IMAGE_UINT
246 BIASERR(
"VideoSource::GrabSingle() should not be called, please overload");
251 #ifdef BUILD_IMAGE_CHAR
254 BIASERR(
"VideoSource_Base::GrabSingle() should not be called, please overload");
259 #ifdef BUILD_IMAGE_SHORT
262 BIASERR(
"VideoSource::GrabSingle() should not be called, please overload");
267 #ifdef BUILD_IMAGE_INT
270 BIASERR(
"VideoSource_Base::GrabSingle() should not be called, please overload");
275 #ifdef BUILD_IMAGE_DOUBLE
278 BIASERR(
"VideoSource::GrabSingle() should not be called, please overload");
285 BIASERR(
"VideoSource_Base::AutoMode() should not be called, please overload");
292 BIASERR(
"VideoSource_Base::GetFeature() should not be called, please overload");
298 BIASERR(
"VideoSource_Base::setFeature() should not be called, please overload");
305 BIASERR(
"VideoSource_Base::SetShutter() should not be called, please overload");
311 BIASERR(
"VideoSource_Base::SetGain() should not be called, please overload");
317 BIASERR(
"VideoSource_Base::GetGain() should not be called, please overload");
323 BIASERR(
"VideoSource_Base::GetShutter() should not be called, please overload");
327 BIASERR(
"VideoSource_Base::OnePushAuto() should not be called,please overload");
331 BIASERR(
"VideoSource_Base::SetWhiteBalance() should not be called,please overload");
336 BIASERR(
"VideoSource_Base::SetWhiteBalance() should not be called,please overload");
343 float rGain=0.0, bGain=0.0;
344 int widthHalf, heightHalf;
362 unsigned char mean[3];
365 widthHalf+10, heightHalf+10);
369 while(iterations < 32)
371 BIASCDOUT(D_VS_WHITEB,
"In videosource, SoftwarewhiteBalance pixel: "
372 <<(
int)mean[0]<<
","<<(
int)mean[1]<<
","<<(
int)mean[2]<<endl);
373 if(mean[0] < mean[1])
375 else if(mean[0] > mean[1])
378 if(mean[2] < mean[1])
380 else if(mean[2] > mean[1])
382 BIASCDOUT(D_VS_WHITEB,
"rGain,bGain :"<<rGain<<
","<<bGain<<endl);
386 rgbimg.
SetROI(widthHalf-10, heightHalf-10, widthHalf+10, heightHalf+10);
399 DtDFd_ = open(filename.c_str(),O_WRONLY | O_CREAT , 0644);
401 DtDFd_ = open(filename.c_str(),O_WRONLY | O_CREAT | O_DIRECT, 0644);
406 BIASERR(
"Can not open/create file ");
407 perror(filename.c_str());
411 fchmod(DtDFd_,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
427 int r = posix_memalign((
void**)bufferPointer, 512,
DtDBufferSize_);
434 BIASDOUT(D_DTD,
"Width, height, channelcount, BpP: "<<
Width_<<
"x"<<
Height_
455 BIASERR(
"error in poisx_memalign: "<<r);
456 perror(
"posix_memalign");
471 BIASERR(
"Can not write to file with O_DIRECT: ");
472 perror(filename.c_str());
478 BIASERR(
"SetDirectToDisk() not implemented for WIN32");
485 const long int &sec,
const long int &usec)
495 unsigned int chunksize = 20 * 1024;
498 if (lastchunksize>0) numchunks++;
500 cout <<
"Chunk size: "<<chunksize<<endl;
501 cout <<
"Num chunks: "<<numchunks<<endl;
502 cout <<
"Last chunk: "<<lastchunksize<<endl;
504 unsigned int currentchunksize;
505 for (
unsigned int c=0; c<numchunks; c++) {
506 currentchunksize = c==(numchunks-1) ? lastchunksize :chunksize ;
509 BIASERR(
"Can not write to file with O_DIRECT: ");
514 BIASERR(
"WriteDirect() not implemented for WIN32");
EColorModel
These are the most often used color models.
YUYV422, 2 channels, full luminance Y, subsampled half U,V.
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
Bayer_GRBG, 1 channel RGB image Bayer tile.
virtual int SoftwareWhiteBalance()
Set white balance to optimal value in software.
virtual int InitImage(BIAS::ImageBase &Image)
void GetString(std::string &sUUID) const
writes the UUID into a string object
(16bit) unsigned integer image storage type
char * DtDBuffer_
512 byte aligned buffer, contains VSImageHeader and image data
BIAS::VideoStream::VSImageHeader * DtDImageHeader_
Pointer to the beginning of DtDBuffer_.
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
bool IsControllable_
Must be initialized be the derived classes.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
char * DtDStartOfImage_
Pointer into DtDBuffer after VSImageHeader.
const char * DefaultDevice_
Device name.
void SetColorModel(EColorModel Model)
virtual int GetWhiteBalance(float &rvalue, float &bvalue)
Get white balance as values in interval [0, 100]. */.
int WriteDirect_(const unsigned char *data, const BIAS::UUID &uuid, const long int &sec, const long int &usec)
Bayer_RGGB, 1 channel RGB image Bayer tile.
BIAS::ImageBase::EColorModel ColorMode_
Color mode used by camera.
int DeviceChannel_
Device channel.
bool WaitForNew_
Wait for new frames in GrabSingle()
float BytesPerPixel_
BytesPerPixel cannot be int (e.g. it is 1.5 for YUV420p)
virtual float GetShutter()
Get shutter (exposure time) in seconds.
virtual int SetWhiteBalance(float rvalue, float bvalue)
Set white balance as values in interval [0, 100]. */.
unsigned int GetWidth() const
virtual int SetGain(float g)
Set gain in dB.
YUV420P, 2 channels, full luminance Y, 1 U, 1 V. Y, U and V are grouped together for better compressi...
Todo: Conflict with YUVU model, what does it do?
bool CompleteInitialized_
Complete_initialized_ is set when OpenDevice(), UseChannel() etc. are done.
void GetMeanPixelValue(StorageType mean[])
calculates mean of pixel
invalid not set image storage type
color values, 3 channels, order: blue,green,red
Bayer_BGGR, 1 channel RGB image Bayer tile.
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
Bayer_GBRG, 1 channel RGB image Bayer tile.
std::string Identifier_
Verbose camera descriptor.
ROI * GetROI()
Returns a pointer to the roi object.
bool Grabbing_
Grabbing flag is set and unset in GrabSingle() methods.
virtual float GetGain()
Get gain in dB.
virtual int OpenDevice()
selects the first available device to open (e.g.
virtual int AutoMode(int a, bool b)
Use this to enable/disable any automatic modes addressed via enumerations.
virtual int SetShutter(float exptime)
Set shutter (exposure time) in seconds.
virtual unsigned int GetFeature(int feature)
This function is used to query features like shutter, zoom, etc.
float FramesPerSecond_
Capturing framerate.
color values, 3 channels, order: red,green,blue
int SetDirectToDisk(const std::string &filename)
Enables the very fast direct-to-disk mode.
unsigned int GetHeight() const
double minContrast_
Feature ranges.
virtual int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
The image template class for specific storage types.
bool DirectToDisk_
Write directly to disk.
bool bExternalTrigger_
External trigger flag.
unsigned int DtDBufferSize_
Buffer size must be multiple of 512.
int SetROI(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
deprecated, use SetROICorners()
bool Active_
Active flag is set in PreGrab() und unset in PostGrab()
virtual int SetFeature(int feature, unsigned int value)
This function is used to control features like shutter, zoom, etc.
RGBA, 4 channels, order: red,green,blue,alpha.
virtual int GetAllDevices(std::vector< std::string > &devices)
virtual int GrabSingle(BIAS::Camera< unsigned char > &image)
virtual int PostGrab()
Stop anything started in PreGrab()
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
virtual int CloseDevice()
unsigned int ImageSize_
Image size, useful for allocating and copying memory.
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
Checks for VideoSource capabilities.
int DtDFd_
File descriptor for direct-to-disk mode.
interface class for producing/storing Universally Unique IDentifiers
virtual int OnePushAuto(int feature)
This is the base class for images in BIAS.
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
virtual int GetCapabilities(VideoSourceCapabilities &caps)
Use this method to learn something about the capabilities of the source (only useful for V4L sources...
BGRA color values, 4 channels, order: blue,green,red,alpha.