Unable to open new AVT/PVAPI cameras: file Cap_pvapi.dll (Bug #3947)
Description
Newer versions of AVT cameras take longer to initialize than previous versions. Therefore, a delay of 1000 msec is OK for older versions; but it not enough for newer versions. The fix is in file Cap_pvapi.cpp in the function
bool CvCaptureCAM_PvAPI::open( int index ), as follows:
if (PvInitialize()) { } //return false; Sleep(1000); //close();
Simply change this value to 2000:
if (PvInitialize()) { } //return false; Sleep(2000); //close();
A better approach would be to poll PvInitialize() up to 2000 mSec so that older cameras do not suffer a penalty.
Associated revisions
Merge pull request #3947 from tcavallari:patch-1
History
Updated by Steven Puttemans over 10 years ago
I would say this implementation still lacks performance. What we did (referring to our AVT Manta Camera code snippet here: https://github.com/StevenPuttemans/opencv_tryout_code/blob/master/camera_interfacing/AVT_manta_camera.cpp ) was creating a polling loop that checks if there is a camera found each 15 ms. This way you will never need to wait to long. The suggested code should thus be changed according to me to something like
if(!PvInitialize()){ // Wait for the response from a camera after the initialization of the driver // This is done by checking if camera's are found yet while(PvCameraCount() == 0) { waitKey(15); } // Continue }
If you agree we could provide a pull request for this!
- Assignee set to Steven Puttemans
- Status changed from New to Open
Updated by Steven Puttemans over 10 years ago
PR submitted!
- Pull request set to https://github.com/Itseez/opencv/pull/3322
Updated by Steven Puttemans over 10 years ago
@Shai,
I do encourage you to jump into the PR and help me solve some more issues.
As far as I see it, the current code will NEVER work with my AVT Manta Camera.
I have a working interface with PvAPI as a reference: https://github.com/StevenPuttemans/opencv_tryout_code/blob/master/camera_interfacing/AVT_manta_camera.cpp
It seems that even basic stuff like the initialization is done incorrectly. Looking at for example the initialization here we see it is done
if (PvInitialize()) { }
But actually if I want the initialization to work, I need to change it to
if (!PvInitialize()) { }
Experienced something similar?
Updated by Shai Vaingast over 10 years ago
I have a problem with waitKey() as it is not defined in this scope. Assuming we can get around this issue, there are still two things to address. (1) That while loop is an infinite loop. To avoid a hang, a better approach would be to add a timer to the loop (implemented with a counter). (2) This code only allows one PVAPI camera to be opened. Instead of checking whether PvCameraCount() is zero, it's better to record the value before initalizing the camera and then checking for an increment. This can be done with the variable numCameras which is defined later in the code.
Here's my suggestion:
int iInitializeTimeout = 5000/15; unsigned int numCameras = PvCameraList(cameraList, MAX_CAMERAS, NULL); if (!PvInitialize()) { while((PvCameraCount() != (numCameras+1)) && (iInitializeTimeout--)) { waitKey(15); } } numCameras = PvCameraList(cameraList, MAX_CAMERAS, NULL);
I was unable to test this implementation due to the waitKey() function not defined in this scope error.
Updated by Steven Puttemans over 10 years ago
I sent you a mail with the PR i am creating. As to your remarks
1) Agreed, it had to be cvWaitKey because the capture still addresses the old C - API.
2) I do understand why you would create a time-out. However I would then simply set that at a fixed 500, which means 5000 ms of initialisation time, which is far more enough for most cameras. When that triggers I will push out an error message.
3) I agree that this could only open a single cam, your solution seems better indeed.
Lets discuss this further inside the PR link I sent you.
Updated by Philip L almost 10 years ago
PR was merged and solution should also be already in OpenCV 3.0
- Status changed from Open to Done
- % Done changed from 0 to 100