Reputation: 21
I am working on a project that requires the control of the PTZ function of my IP camera through the UI. I am currently using a D-Link DCS-5020L cloud camera, Microsoft Visual Studio 2017 and OpenCV 3.3 for my setup.
I am still new to c++ and OpenCV but my project requires the use of it. I am able to access the camera feed but I'm not sure how to control the functions of the camera using C++ code through OpenCV or if OpenCV is even needed.
Is there a C++ code to control the PTZ functions of the IP camera?
This is my code for attaining the video output, if necessary.
// VIDEO CAPTURE //
Mat frame;
VideoCapture cap("http://username:password@IPADDRESS:PORT/video.cgi?resolution=640x360&req_fps=30&.mjpg");
if (!cap.isOpened()) //EXIT PROGRAM IF FAILED
{
cout << "CAMERA UNAVAILABLE" << endl;
return -1;
}
while (1)
{
bool bSuccess = cap.read(frame); //READ NEW FRAME FROM VIDEO
if (!bSuccess) //BREAK LOOP IF FAILED
{
cout << "UNABLE TO DISPLAY VIDEO" << endl;
break;
}
}
Any help is appreciated. Thank you.
Upvotes: 2
Views: 4184
Reputation: 679
I used the software "ONVIF Device Manager" to watch the trafic controlling PTZ
In my case using V380pro Camera i found that you can use XML service for PTZ from Postman or with SoapUI the parameters are by example:
method:POST
url:http://<user>:<password>@<ip_address>:8899/onvif/PTZ
body:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ContinuousMove xmlns="http://www.onvif.org/ver20/ptz/wsdl">
<ProfileToken>stream0_0</ProfileToken>
<Velocity>
<PanTilt x="-0.5" y="0" xmlns="http://www.onvif.org/ver10/schema"/>
</Velocity>
</ContinuousMove>
</s:Body>
</s:Envelope>
Upvotes: 0
Reputation: 181
Usually, PTZ functions are software implemented on the server running in the cam. Some older cameras used to ship with an activeX control. These functions can be accessed by getting or posting to a url relative to the camera.
For Your camera, you should be able to post the controls on the following url:
http://<ip>/pantiltcontrol.cgi
Available controls:
POST parameters
PanSingleMoveDegree (default 5)
TiltSingleMoveDegree (default 5)
PanTiltSingleMove
Values for PanTiltSingleMove (based on the web UI controls):
Top 1
Top right 2
Right 5
Bottom right 8
Bottom 7
Bottom left 6
Left 3
Top left 0
Home (reset) 4
So a typical post example using curl to change the pan-tilt, should be similar to this:
curl --user <username>:<password> --user-agent "user" --data "PanSingleMoveDegree=5&TiltSingleMoveDegree=5&PanTiltSingleMove=5" http://<ip>/pantiltcontrol.cgi
For a quick test using your web browser, You should Be able to do the same thing using a get request for the following structured url:
http://<username>:<password>@<ip>/pantiltcontrol.cgi?PanSingleMoveDegree=5&TiltSingleMoveDegree=5&PanTiltSingleMove=5
Now, Back to your question. All you need to control PTZ in C++, is to web query the mentioned urls. So this should be your searching point.
Many Answers for this topic are already on stack overflow. This is the first result I got while googling "c++ http get post". How do you make a HTTP request with C++?
Upvotes: 1