|
|
@ -60,6 +60,7 @@ |
|
|
|
#ifdef WIN32 |
|
|
|
#ifdef WIN32 |
|
|
|
# include <io.h> |
|
|
|
# include <io.h> |
|
|
|
#else |
|
|
|
#else |
|
|
|
|
|
|
|
# include <time.h> |
|
|
|
# include <unistd.h> |
|
|
|
# include <unistd.h> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
@ -106,18 +107,14 @@ protected: |
|
|
|
} tCamera; |
|
|
|
} tCamera; |
|
|
|
|
|
|
|
|
|
|
|
IplImage *frame; |
|
|
|
IplImage *frame; |
|
|
|
IplImage *grayframe; |
|
|
|
|
|
|
|
tCamera Camera; |
|
|
|
tCamera Camera; |
|
|
|
tPvErr Errcode; |
|
|
|
tPvErr Errcode; |
|
|
|
bool monocrome; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CvCaptureCAM_PvAPI::CvCaptureCAM_PvAPI() |
|
|
|
CvCaptureCAM_PvAPI::CvCaptureCAM_PvAPI() |
|
|
|
{ |
|
|
|
{ |
|
|
|
monocrome=false; |
|
|
|
|
|
|
|
frame = NULL; |
|
|
|
frame = NULL; |
|
|
|
grayframe = NULL; |
|
|
|
|
|
|
|
memset(&this->Camera, 0, sizeof(this->Camera)); |
|
|
|
memset(&this->Camera, 0, sizeof(this->Camera)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -190,13 +187,6 @@ bool CvCaptureCAM_PvAPI::open( int index ) |
|
|
|
tPvUint32 frameWidth, frameHeight; |
|
|
|
tPvUint32 frameWidth, frameHeight; |
|
|
|
unsigned long maxSize; |
|
|
|
unsigned long maxSize; |
|
|
|
|
|
|
|
|
|
|
|
// By Default, try to set the pixel format to Mono8. This can be changed later
|
|
|
|
|
|
|
|
// via calls to setProperty. Some colour cameras (i.e. the Manta line) have a default
|
|
|
|
|
|
|
|
// image mode of Bayer8, which is currently unsupported, so Mono8 is a safe bet for
|
|
|
|
|
|
|
|
// startup.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
monocrome = (PvAttrEnumSet(Camera.Handle, "PixelFormat", "Mono8") == ePvErrSuccess); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PvAttrUint32Get(Camera.Handle, "Width", &frameWidth); |
|
|
|
PvAttrUint32Get(Camera.Handle, "Width", &frameWidth); |
|
|
|
PvAttrUint32Get(Camera.Handle, "Height", &frameHeight); |
|
|
|
PvAttrUint32Get(Camera.Handle, "Height", &frameHeight); |
|
|
|
|
|
|
|
|
|
|
@ -229,15 +219,9 @@ bool CvCaptureCAM_PvAPI::grabFrame() |
|
|
|
|
|
|
|
|
|
|
|
IplImage* CvCaptureCAM_PvAPI::retrieveFrame(int) |
|
|
|
IplImage* CvCaptureCAM_PvAPI::retrieveFrame(int) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (PvCaptureWaitForFrameDone(Camera.Handle, &(Camera.Frame), 1000) == ePvErrSuccess) |
|
|
|
if (PvCaptureWaitForFrameDone(Camera.Handle, &(Camera.Frame), 1000) == ePvErrSuccess) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!monocrome) |
|
|
|
return frame; |
|
|
|
{ |
|
|
|
|
|
|
|
cvMerge(grayframe,grayframe,grayframe,NULL,frame); |
|
|
|
|
|
|
|
return frame; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return grayframe; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else return NULL; |
|
|
|
else return NULL; |
|
|
|
} |
|
|
|
} |
|
|
@ -254,11 +238,6 @@ double CvCaptureCAM_PvAPI::getProperty( int property_id ) const |
|
|
|
case CV_CAP_PROP_FRAME_HEIGHT: |
|
|
|
case CV_CAP_PROP_FRAME_HEIGHT: |
|
|
|
PvAttrUint32Get(Camera.Handle, "Height", &nTemp); |
|
|
|
PvAttrUint32Get(Camera.Handle, "Height", &nTemp); |
|
|
|
return (double)nTemp; |
|
|
|
return (double)nTemp; |
|
|
|
case CV_CAP_PROP_MONOCROME: |
|
|
|
|
|
|
|
if (monocrome) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
case CV_CAP_PROP_EXPOSURE: |
|
|
|
case CV_CAP_PROP_EXPOSURE: |
|
|
|
PvAttrUint32Get(Camera.Handle,"ExposureValue",&nTemp); |
|
|
|
PvAttrUint32Get(Camera.Handle,"ExposureValue",&nTemp); |
|
|
|
return (double)nTemp; |
|
|
|
return (double)nTemp; |
|
|
@ -312,6 +291,25 @@ double CvCaptureCAM_PvAPI::getProperty( int property_id ) const |
|
|
|
case CV_CAP_PROP_PVAPI_BINNINGY: |
|
|
|
case CV_CAP_PROP_PVAPI_BINNINGY: |
|
|
|
PvAttrUint32Get(Camera.Handle,"BinningY",&nTemp); |
|
|
|
PvAttrUint32Get(Camera.Handle,"BinningY",&nTemp); |
|
|
|
return (double)nTemp; |
|
|
|
return (double)nTemp; |
|
|
|
|
|
|
|
case CV_CAP_PROP_PVAPI_PIXELFORMAT: |
|
|
|
|
|
|
|
char pixelFormat[256]; |
|
|
|
|
|
|
|
PvAttrEnumGet(Camera.Handle, "PixelFormat", pixelFormat,256,NULL); |
|
|
|
|
|
|
|
if (strcmp(pixelFormat, "Mono8")==0) |
|
|
|
|
|
|
|
return 1.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Mono16")==0) |
|
|
|
|
|
|
|
return 2.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Bayer8")==0) |
|
|
|
|
|
|
|
return 3.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Bayer16")==0) |
|
|
|
|
|
|
|
return 4.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Rgb24")==0) |
|
|
|
|
|
|
|
return 5.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Bgr24")==0) |
|
|
|
|
|
|
|
return 6.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Rgba32")==0) |
|
|
|
|
|
|
|
return 7.0; |
|
|
|
|
|
|
|
else if (strcmp(pixelFormat, "Bgra32")==0) |
|
|
|
|
|
|
|
return 8.0; |
|
|
|
} |
|
|
|
} |
|
|
|
return -1.0; |
|
|
|
return -1.0; |
|
|
|
} |
|
|
|
} |
|
|
@ -359,21 +357,6 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value ) |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case CV_CAP_PROP_MONOCROME: |
|
|
|
|
|
|
|
if (value==1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char pixelFormat[256]; |
|
|
|
|
|
|
|
PvAttrEnumGet(Camera.Handle, "PixelFormat", pixelFormat,256,NULL); |
|
|
|
|
|
|
|
if ((strcmp(pixelFormat, "Mono8")==0) || strcmp(pixelFormat, "Mono16")==0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
monocrome=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
monocrome=false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CV_CAP_PROP_EXPOSURE: |
|
|
|
case CV_CAP_PROP_EXPOSURE: |
|
|
|
if ((PvAttrUint32Set(Camera.Handle,"ExposureValue",(tPvUint32)value)==ePvErrSuccess)) |
|
|
|
if ((PvAttrUint32Set(Camera.Handle,"ExposureValue",(tPvUint32)value)==ePvErrSuccess)) |
|
|
|
break; |
|
|
|
break; |
|
|
@ -449,6 +432,51 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value ) |
|
|
|
break; |
|
|
|
break; |
|
|
|
else |
|
|
|
else |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
case CV_CAP_PROP_PVAPI_PIXELFORMAT: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
cv::String pixelFormat; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (value==1) |
|
|
|
|
|
|
|
pixelFormat = "Mono8"; |
|
|
|
|
|
|
|
else if (value==2) |
|
|
|
|
|
|
|
pixelFormat = "Mono16"; |
|
|
|
|
|
|
|
else if (value==3) |
|
|
|
|
|
|
|
pixelFormat = "Bayer8"; |
|
|
|
|
|
|
|
else if (value==4) |
|
|
|
|
|
|
|
pixelFormat = "Bayer16"; |
|
|
|
|
|
|
|
else if (value==5) |
|
|
|
|
|
|
|
pixelFormat = "Rgb24"; |
|
|
|
|
|
|
|
else if (value==6) |
|
|
|
|
|
|
|
pixelFormat = "Bgr24"; |
|
|
|
|
|
|
|
else if (value==7) |
|
|
|
|
|
|
|
pixelFormat = "Rgba32"; |
|
|
|
|
|
|
|
else if (value==8) |
|
|
|
|
|
|
|
pixelFormat = "Bgra32"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((PvAttrEnumSet(Camera.Handle,"PixelFormat", pixelFormat.c_str())==ePvErrSuccess)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
tPvUint32 currWidth; |
|
|
|
|
|
|
|
tPvUint32 currHeight; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PvAttrUint32Get(Camera.Handle, "Width", &currWidth); |
|
|
|
|
|
|
|
PvAttrUint32Get(Camera.Handle, "Height", &currHeight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stopCapture(); |
|
|
|
|
|
|
|
// Reallocate Frames
|
|
|
|
|
|
|
|
if (!resizeCaptureFrame(currWidth, currHeight)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
startCapture(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startCapture(); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -495,13 +523,6 @@ bool CvCaptureCAM_PvAPI::resizeCaptureFrame (int frameWidth, int frameHeight) |
|
|
|
tPvUint32 sensorHeight; |
|
|
|
tPvUint32 sensorHeight; |
|
|
|
tPvUint32 sensorWidth; |
|
|
|
tPvUint32 sensorWidth; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (grayframe) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
cvReleaseImage(&grayframe); |
|
|
|
|
|
|
|
grayframe = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (frame) |
|
|
|
if (frame) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cvReleaseImage(&frame); |
|
|
|
cvReleaseImage(&frame); |
|
|
@ -544,31 +565,34 @@ bool CvCaptureCAM_PvAPI::resizeCaptureFrame (int frameWidth, int frameHeight) |
|
|
|
PvAttrUint32Get(Camera.Handle, "TotalBytesPerFrame", &frameSize); |
|
|
|
PvAttrUint32Get(Camera.Handle, "TotalBytesPerFrame", &frameSize); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(pixelFormat, "Mono8")==0) |
|
|
|
if ( (strcmp(pixelFormat, "Mono8")==0) || (strcmp(pixelFormat, "Bayer8")==0) ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
grayframe = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 1); |
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 1); |
|
|
|
grayframe->widthStep = (int)frameWidth; |
|
|
|
frame->widthStep = (int)frameWidth; |
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 3); |
|
|
|
|
|
|
|
frame->widthStep = (int)frameWidth*3; |
|
|
|
|
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
Camera.Frame.ImageBuffer = grayframe->imageData; |
|
|
|
Camera.Frame.ImageBuffer = frame->imageData; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (strcmp(pixelFormat, "Mono16")==0) |
|
|
|
else if ( (strcmp(pixelFormat, "Mono16")==0) || (strcmp(pixelFormat, "Bayer16")==0) ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
grayframe = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_16U, 1); |
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_16U, 1); |
|
|
|
grayframe->widthStep = (int)frameWidth; |
|
|
|
frame->widthStep = (int)frameWidth*2; |
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_16U, 3); |
|
|
|
|
|
|
|
frame->widthStep = (int)frameWidth*3; |
|
|
|
|
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
Camera.Frame.ImageBuffer = grayframe->imageData; |
|
|
|
Camera.Frame.ImageBuffer = frame->imageData; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (strcmp(pixelFormat, "Bgr24")==0) |
|
|
|
else if ( (strcmp(pixelFormat, "Rgb24")==0) || (strcmp(pixelFormat, "Bgr24")==0) ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 3); |
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 3); |
|
|
|
frame->widthStep = (int)frameWidth*3; |
|
|
|
frame->widthStep = (int)frameWidth*3; |
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
Camera.Frame.ImageBuffer = frame->imageData; |
|
|
|
Camera.Frame.ImageBuffer = frame->imageData; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if ( (strcmp(pixelFormat, "Rgba32")==0) || (strcmp(pixelFormat, "Bgra32")==0) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 4); |
|
|
|
|
|
|
|
frame->widthStep = (int)frameWidth*4; |
|
|
|
|
|
|
|
Camera.Frame.ImageBufferSize = frameSize; |
|
|
|
|
|
|
|
Camera.Frame.ImageBuffer = frame->imageData; |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|