Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
50bebd6f
Commit
50bebd6f
authored
Nov 28, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #166 from askforeric:pvapi_updates
parents
61a40ddf
39234843
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
205 additions
and
74 deletions
+205
-74
cap_pvapi.cpp
modules/highgui/src/cap_pvapi.cpp
+205
-74
No files found.
modules/highgui/src/cap_pvapi.cpp
View file @
50bebd6f
...
@@ -95,6 +95,10 @@ protected:
...
@@ -95,6 +95,10 @@ protected:
virtual
void
Sleep
(
unsigned
int
time
);
virtual
void
Sleep
(
unsigned
int
time
);
#endif
#endif
void
stopCapture
();
bool
startCapture
();
bool
resizeCaptureFrame
(
int
frameWidth
,
int
frameHeight
);
typedef
struct
typedef
struct
{
{
unsigned
long
UID
;
unsigned
long
UID
;
...
@@ -113,6 +117,8 @@ protected:
...
@@ -113,6 +117,8 @@ protected:
CvCaptureCAM_PvAPI
::
CvCaptureCAM_PvAPI
()
CvCaptureCAM_PvAPI
::
CvCaptureCAM_PvAPI
()
{
{
monocrome
=
false
;
monocrome
=
false
;
frame
=
NULL
;
grayframe
=
NULL
;
memset
(
&
this
->
Camera
,
0
,
sizeof
(
this
->
Camera
));
memset
(
&
this
->
Camera
,
0
,
sizeof
(
this
->
Camera
));
}
}
...
@@ -132,8 +138,7 @@ void CvCaptureCAM_PvAPI::Sleep(unsigned int time)
...
@@ -132,8 +138,7 @@ void CvCaptureCAM_PvAPI::Sleep(unsigned int time)
void
CvCaptureCAM_PvAPI
::
close
()
void
CvCaptureCAM_PvAPI
::
close
()
{
{
// Stop the acquisition & free the camera
// Stop the acquisition & free the camera
PvCommandRun
(
Camera
.
Handle
,
"AcquisitionStop"
);
stopCapture
();
PvCaptureEnd
(
Camera
.
Handle
);
PvCameraClose
(
Camera
.
Handle
);
PvCameraClose
(
Camera
.
Handle
);
PvUnInitialize
();
PvUnInitialize
();
}
}
...
@@ -162,7 +167,8 @@ bool CvCaptureCAM_PvAPI::open( int index )
...
@@ -162,7 +167,8 @@ bool CvCaptureCAM_PvAPI::open( int index )
Camera
.
UID
=
cameraList
[
index
].
UniqueId
;
Camera
.
UID
=
cameraList
[
index
].
UniqueId
;
if
(
!
PvCameraInfo
(
Camera
.
UID
,
&
camInfo
)
&&
!
PvCameraIpSettingsGet
(
Camera
.
UID
,
&
ipSettings
))
{
if
(
!
PvCameraInfo
(
Camera
.
UID
,
&
camInfo
)
&&
!
PvCameraIpSettingsGet
(
Camera
.
UID
,
&
ipSettings
))
{
/*
/*
struct in_addr addr;
struct in_addr addr;
addr.s_addr = ipSettings.CurrentIpAddress;
addr.s_addr = ipSettings.CurrentIpAddress;
...
@@ -173,7 +179,8 @@ bool CvCaptureCAM_PvAPI::open( int index )
...
@@ -173,7 +179,8 @@ bool CvCaptureCAM_PvAPI::open( int index )
printf("Current gateway:\t%s\n",inet_ntoa(addr));
printf("Current gateway:\t%s\n",inet_ntoa(addr));
*/
*/
}
}
else
{
else
{
fprintf
(
stderr
,
"ERROR: could not retrieve camera IP settings.
\n
"
);
fprintf
(
stderr
,
"ERROR: could not retrieve camera IP settings.
\n
"
);
return
false
;
return
false
;
}
}
...
@@ -181,73 +188,33 @@ bool CvCaptureCAM_PvAPI::open( int index )
...
@@ -181,73 +188,33 @@ bool CvCaptureCAM_PvAPI::open( int index )
if
(
PvCameraOpen
(
Camera
.
UID
,
ePvAccessMaster
,
&
(
Camera
.
Handle
))
==
ePvErrSuccess
)
if
(
PvCameraOpen
(
Camera
.
UID
,
ePvAccessMaster
,
&
(
Camera
.
Handle
))
==
ePvErrSuccess
)
{
{
tPvUint32
frameWidth
,
frameHeight
;
//Set Pixel Format to BRG24 to follow conventions
/*Errcode = PvAttrEnumSet(Camera.Handle, "PixelFormat", "Bgr24");
if (Errcode != ePvErrSuccess)
{
fprintf(stderr, "PvAPI: couldn't set PixelFormat to Bgr24\n");
return NULL;
}
*/
tPvUint32
frameWidth
,
frameHeight
,
frameSize
;
unsigned
long
maxSize
;
unsigned
long
maxSize
;
char
pixelFormat
[
256
];
PvAttrUint32Get
(
Camera
.
Handle
,
"TotalBytesPerFrame"
,
&
frameSize
);
// 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
);
PvAttrEnumGet
(
Camera
.
Handle
,
"PixelFormat"
,
pixelFormat
,
256
,
NULL
);
// Determine the maximum packet size supported by the system (ethernet adapter)
// and then configure the camera to use this value. If the system's NIC only supports
// an MTU of 1500 or lower, this will automatically configure an MTU of 1500.
// 8228 is the optimal size described by the API in order to enable jumbo frames
maxSize
=
8228
;
maxSize
=
8228
;
//PvAttrUint32Get(Camera.Handle,"PacketSize",&maxSize);
//PvAttrUint32Get(Camera.Handle,"PacketSize",&maxSize);
if
(
PvCaptureAdjustPacketSize
(
Camera
.
Handle
,
maxSize
)
!=
ePvErrSuccess
)
if
(
PvCaptureAdjustPacketSize
(
Camera
.
Handle
,
maxSize
)
!=
ePvErrSuccess
)
return
false
;
return
false
;
if
(
strcmp
(
pixelFormat
,
"Mono8"
)
==
0
)
{
grayframe
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_8U
,
1
);
grayframe
->
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
.
ImageBuffer
=
grayframe
->
imageData
;
}
else
if
(
strcmp
(
pixelFormat
,
"Mono16"
)
==
0
)
{
grayframe
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_16U
,
1
);
grayframe
->
widthStep
=
(
int
)
frameWidth
;
frame
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_16U
,
3
);
frame
->
widthStep
=
(
int
)
frameWidth
*
3
;
Camera
.
Frame
.
ImageBufferSize
=
frameSize
;
Camera
.
Frame
.
ImageBuffer
=
grayframe
->
imageData
;
}
else
if
(
strcmp
(
pixelFormat
,
"Bgr24"
)
==
0
)
{
frame
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_8U
,
3
);
frame
->
widthStep
=
(
int
)
frameWidth
*
3
;
Camera
.
Frame
.
ImageBufferSize
=
frameSize
;
Camera
.
Frame
.
ImageBuffer
=
frame
->
imageData
;
}
else
return
false
;
// Start the camera
PvCaptureStart
(
Camera
.
Handle
);
// Set the camera to capture continuously
resizeCaptureFrame
(
frameWidth
,
frameHeight
);
if
(
PvAttrEnumSet
(
Camera
.
Handle
,
"AcquisitionMode"
,
"Continuous"
)
!=
ePvErrSuccess
)
{
fprintf
(
stderr
,
"Could not set Prosilica Acquisition Mode
\n
"
);
return
false
;
}
if
(
PvCommandRun
(
Camera
.
Handle
,
"AcquisitionStart"
)
!=
ePvErrSuccess
)
return
startCapture
();
{
fprintf
(
stderr
,
"Could not start Prosilica acquisition
\n
"
);
return
false
;
}
if
(
PvAttrEnumSet
(
Camera
.
Handle
,
"FrameStartTriggerMode"
,
"Freerun"
)
!=
ePvErrSuccess
)
{
fprintf
(
stderr
,
"Error setting Prosilica trigger to
\"
Freerun
\"
"
);
return
false
;
}
return
true
;
}
}
fprintf
(
stderr
,
"Error cannot open camera
\n
"
);
fprintf
(
stderr
,
"Error cannot open camera
\n
"
);
return
false
;
return
false
;
...
@@ -264,8 +231,10 @@ bool CvCaptureCAM_PvAPI::grabFrame()
...
@@ -264,8 +231,10 @@ 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
)
{
{
if
(
!
monocrome
)
{
cvMerge
(
grayframe
,
grayframe
,
grayframe
,
NULL
,
frame
);
cvMerge
(
grayframe
,
grayframe
,
grayframe
,
NULL
,
frame
);
return
frame
;
return
frame
;
}
}
...
@@ -297,16 +266,21 @@ double CvCaptureCAM_PvAPI::getProperty( int property_id )
...
@@ -297,16 +266,21 @@ double CvCaptureCAM_PvAPI::getProperty( int property_id )
char
mEnable
[
2
];
char
mEnable
[
2
];
char
mIp
[
11
];
char
mIp
[
11
];
PvAttrEnumGet
(
Camera
.
Handle
,
"MulticastEnable"
,
mEnable
,
sizeof
(
mEnable
),
NULL
);
PvAttrEnumGet
(
Camera
.
Handle
,
"MulticastEnable"
,
mEnable
,
sizeof
(
mEnable
),
NULL
);
if
(
strcmp
(
mEnable
,
"Off"
)
==
0
)
{
if
(
strcmp
(
mEnable
,
"Off"
)
==
0
)
{
return
-
1
;
return
-
1
;
}
}
else
{
else
{
long
int
ip
;
long
int
ip
;
int
a
,
b
,
c
,
d
;
int
a
,
b
,
c
,
d
;
PvAttrStringGet
(
Camera
.
Handle
,
"MulticastIPAddress"
,
mIp
,
sizeof
(
mIp
),
NULL
);
PvAttrStringGet
(
Camera
.
Handle
,
"MulticastIPAddress"
,
mIp
,
sizeof
(
mIp
),
NULL
);
sscanf
(
mIp
,
"%d.%d.%d.%d"
,
&
a
,
&
b
,
&
c
,
&
d
);
ip
=
((
a
*
256
+
b
)
*
256
+
c
)
*
256
+
d
;
sscanf
(
mIp
,
"%d.%d.%d.%d"
,
&
a
,
&
b
,
&
c
,
&
d
);
ip
=
((
a
*
256
+
b
)
*
256
+
c
)
*
256
+
d
;
return
(
double
)
ip
;
return
(
double
)
ip
;
}
}
case
CV_CAP_PROP_GAIN
:
PvAttrUint32Get
(
Camera
.
Handle
,
"GainValue"
,
&
nTemp
);
return
(
double
)
nTemp
;
}
}
return
-
1.0
;
return
-
1.0
;
}
}
...
@@ -315,19 +289,50 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
...
@@ -315,19 +289,50 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
{
{
switch
(
property_id
)
switch
(
property_id
)
{
{
/* TODO: Camera works, but IplImage must be modified for the new size
case
CV_CAP_PROP_FRAME_WIDTH
:
case
CV_CAP_PROP_FRAME_WIDTH
:
PvAttrUint32Set(Camera.Handle, "Width", (tPvUint32)value);
{
tPvUint32
currHeight
;
PvAttrUint32Get
(
Camera
.
Handle
,
"Height"
,
&
currHeight
);
stopCapture
();
// Reallocate Frames
if
(
!
resizeCaptureFrame
(
value
,
currHeight
))
{
startCapture
();
return
false
;
}
startCapture
();
break
;
break
;
}
case
CV_CAP_PROP_FRAME_HEIGHT
:
case
CV_CAP_PROP_FRAME_HEIGHT
:
PvAttrUint32Set(Camera.Handle, "Heigth", (tPvUint32)value);
{
tPvUint32
currWidth
;
PvAttrUint32Get
(
Camera
.
Handle
,
"Width"
,
&
currWidth
);
stopCapture
();
// Reallocate Frames
if
(
!
resizeCaptureFrame
(
value
,
currWidth
))
{
startCapture
();
return
false
;
}
startCapture
();
break
;
break
;
*/
}
case
CV_CAP_PROP_MONOCROME
:
case
CV_CAP_PROP_MONOCROME
:
if
(
value
==
1
)
{
if
(
value
==
1
)
{
char
pixelFormat
[
256
];
char
pixelFormat
[
256
];
PvAttrEnumGet
(
Camera
.
Handle
,
"PixelFormat"
,
pixelFormat
,
256
,
NULL
);
PvAttrEnumGet
(
Camera
.
Handle
,
"PixelFormat"
,
pixelFormat
,
256
,
NULL
);
if
((
strcmp
(
pixelFormat
,
"Mono8"
)
==
0
)
||
strcmp
(
pixelFormat
,
"Mono16"
)
==
0
)
{
if
((
strcmp
(
pixelFormat
,
"Mono8"
)
==
0
)
||
strcmp
(
pixelFormat
,
"Mono16"
)
==
0
)
{
monocrome
=
true
;
monocrome
=
true
;
}
}
else
else
...
@@ -342,14 +347,15 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
...
@@ -342,14 +347,15 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
else
else
return
false
;
return
false
;
case
CV_CAP_PROP_PVAPI_MULTICASTIP
:
case
CV_CAP_PROP_PVAPI_MULTICASTIP
:
if
(
value
==-
1
)
if
(
value
==-
1
)
{
{
if
((
PvAttrEnumSet
(
Camera
.
Handle
,
"MulticastEnable"
,
"Off"
)
==
ePvErrSuccess
))
if
((
PvAttrEnumSet
(
Camera
.
Handle
,
"MulticastEnable"
,
"Off"
)
==
ePvErrSuccess
))
break
;
break
;
else
else
return
false
;
return
false
;
}
}
else
{
else
{
std
::
string
ip
=
cv
::
format
(
"%d.%d.%d.%d"
,
((
int
)
value
>>
24
)
&
255
,
((
int
)
value
>>
16
)
&
255
,
((
int
)
value
>>
8
)
&
255
,
(
int
)
value
&
255
);
std
::
string
ip
=
cv
::
format
(
"%d.%d.%d.%d"
,
((
int
)
value
>>
24
)
&
255
,
((
int
)
value
>>
16
)
&
255
,
((
int
)
value
>>
8
)
&
255
,
(
int
)
value
&
255
);
if
((
PvAttrEnumSet
(
Camera
.
Handle
,
"MulticastEnable"
,
"On"
)
==
ePvErrSuccess
)
&&
if
((
PvAttrEnumSet
(
Camera
.
Handle
,
"MulticastEnable"
,
"On"
)
==
ePvErrSuccess
)
&&
(
PvAttrStringSet
(
Camera
.
Handle
,
"MulticastIPAddress"
,
ip
.
c_str
())
==
ePvErrSuccess
))
(
PvAttrStringSet
(
Camera
.
Handle
,
"MulticastIPAddress"
,
ip
.
c_str
())
==
ePvErrSuccess
))
...
@@ -357,12 +363,137 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
...
@@ -357,12 +363,137 @@ bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
else
else
return
false
;
return
false
;
}
}
case
CV_CAP_PROP_GAIN
:
if
(
PvAttrUint32Set
(
Camera
.
Handle
,
"GainValue"
,(
tPvUint32
)
value
)
!=
ePvErrSuccess
)
{
return
false
;
}
break
;
default
:
default
:
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
void
CvCaptureCAM_PvAPI
::
stopCapture
()
{
PvCommandRun
(
Camera
.
Handle
,
"AcquisitionStop"
);
PvCaptureEnd
(
Camera
.
Handle
);
}
bool
CvCaptureCAM_PvAPI
::
startCapture
()
{
// Start the camera
PvCaptureStart
(
Camera
.
Handle
);
// Set the camera to capture continuously
if
(
PvAttrEnumSet
(
Camera
.
Handle
,
"AcquisitionMode"
,
"Continuous"
)
!=
ePvErrSuccess
)
{
fprintf
(
stderr
,
"Could not set PvAPI Acquisition Mode
\n
"
);
return
false
;
}
if
(
PvCommandRun
(
Camera
.
Handle
,
"AcquisitionStart"
)
!=
ePvErrSuccess
)
{
fprintf
(
stderr
,
"Could not start PvAPI acquisition
\n
"
);
return
false
;
}
if
(
PvAttrEnumSet
(
Camera
.
Handle
,
"FrameStartTriggerMode"
,
"Freerun"
)
!=
ePvErrSuccess
)
{
fprintf
(
stderr
,
"Error setting PvAPI trigger to
\"
Freerun
\"
"
);
return
false
;
}
return
true
;
}
bool
CvCaptureCAM_PvAPI
::
resizeCaptureFrame
(
int
frameWidth
,
int
frameHeight
)
{
char
pixelFormat
[
256
];
tPvUint32
frameSize
;
tPvUint32
sensorHeight
;
tPvUint32
sensorWidth
;
if
(
grayframe
)
{
cvReleaseImage
(
&
grayframe
);
grayframe
=
NULL
;
}
if
(
frame
)
{
cvReleaseImage
(
&
frame
);
frame
=
NULL
;
}
if
(
PvAttrUint32Get
(
Camera
.
Handle
,
"SensorWidth"
,
&
sensorWidth
)
!=
ePvErrSuccess
)
{
return
false
;
}
if
(
PvAttrUint32Get
(
Camera
.
Handle
,
"SensorHeight"
,
&
sensorHeight
)
!=
ePvErrSuccess
)
{
return
false
;
}
// Cap out of bounds widths to the max supported by the sensor
if
((
frameWidth
<
0
)
||
((
tPvUint32
)
frameWidth
>
sensorWidth
))
{
frameWidth
=
sensorWidth
;
}
if
((
frameHeight
<
0
)
||
((
tPvUint32
)
frameHeight
>
sensorHeight
))
{
frameHeight
=
sensorHeight
;
}
if
(
PvAttrUint32Set
(
Camera
.
Handle
,
"Height"
,
frameHeight
)
!=
ePvErrSuccess
)
{
return
false
;
}
if
(
PvAttrUint32Set
(
Camera
.
Handle
,
"Width"
,
frameWidth
)
!=
ePvErrSuccess
)
{
return
false
;
}
PvAttrEnumGet
(
Camera
.
Handle
,
"PixelFormat"
,
pixelFormat
,
256
,
NULL
);
PvAttrUint32Get
(
Camera
.
Handle
,
"TotalBytesPerFrame"
,
&
frameSize
);
if
(
strcmp
(
pixelFormat
,
"Mono8"
)
==
0
)
{
grayframe
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_8U
,
1
);
grayframe
->
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
.
ImageBuffer
=
grayframe
->
imageData
;
}
else
if
(
strcmp
(
pixelFormat
,
"Mono16"
)
==
0
)
{
grayframe
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_16U
,
1
);
grayframe
->
widthStep
=
(
int
)
frameWidth
;
frame
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_16U
,
3
);
frame
->
widthStep
=
(
int
)
frameWidth
*
3
;
Camera
.
Frame
.
ImageBufferSize
=
frameSize
;
Camera
.
Frame
.
ImageBuffer
=
grayframe
->
imageData
;
}
else
if
(
strcmp
(
pixelFormat
,
"Bgr24"
)
==
0
)
{
frame
=
cvCreateImage
(
cvSize
((
int
)
frameWidth
,
(
int
)
frameHeight
),
IPL_DEPTH_8U
,
3
);
frame
->
widthStep
=
(
int
)
frameWidth
*
3
;
Camera
.
Frame
.
ImageBufferSize
=
frameSize
;
Camera
.
Frame
.
ImageBuffer
=
frame
->
imageData
;
}
else
return
false
;
return
true
;
}
CvCapture
*
cvCreateCameraCapture_PvAPI
(
int
index
)
CvCapture
*
cvCreateCameraCapture_PvAPI
(
int
index
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment