ONVIF的抓图

    IPC抓拍是个很重要的功能,比如在报警视频联动中需要一张实时的图片,很多SDK不提供抓拍功能,而通过预览抓图,得到的图片已不具有实时性,哪如何得到实时的图片呢?
    现在的IPC基本上都支持ONVIF协议,ONVIF协议除了提供RTSP的URL外,其实也给出了抓拍的URL,从Media的GetSnapshotUri获取,如下:
Description:
A client uses the GetSnapshotUri command to obtain a JPEG snapshot from the device. The returned URI shall remain valid indefinitely even if the profile is changed. The ValidUntilConnect, ValidUntilReboot and Timeout Parameter shall be set accordingly (ValidUntilConnect=false, ValidUntilReboot=false, timeout=PT0S). The URI can be used for acquiring a JPEG image through a HTTP GET operation. The image encoding will always be JPEG regardless of the encoding setting in the media profile. The Jpeg settings (like resolution or quality) may be taken from the profile if suitable. The provided image will be updated automatically and independent from calls to

GetSnapshotUri.

Output:[GetSnapshotUriResponse]
■MediaUri [MediaUri]
■Uri [anyURI]
Stable Uri to be used for requesting the media stream
■InvalidAfterConnect [boolean]
Indicates if the Uri is only valid until the connection is established. The value shall be set to "false".
■InvalidAfterReboot [boolean]
Indicates if the Uri is invalid after a reboot of the device. The value shall be set to "false".
■Timeout [duration]
Duration how long the Uri is valid. This parameter shall be set to PT0S to indicate that this stream URI is indefinitely valid even if the profile changes
    比如:我从测试相机获得的抓拍URL为:http://172.16.200.24/cgi-bin/jpg/image.cgi。
    那如何通过这个地址获得图片呢,其实描述中已经提到,“The URI can be used for acquiring a JPEG image through a HTTP GET operation”,也就是通过HTTP的GET方式获得JPEG图片。
    首先配置一路子码流为MJPEG,如:配3路码率,主码流为H264,子码流为H264和MJPEG;在浏览器上输入得到的抓图URL“http://172.16.200.24/cgi-bin/jpg/image.cgi”,这时会显示出图片,刷新,图片会变化。
    那如何通过C++得到图片呢?MFC里有CInternetSession,CHttpConnection,CHttpFile这些类提供通过HTTP获得数据,其实底层还是调用InternetOpen等WinInet函数,代码详见:http://download.csdn.net/detail/evsqiezi/7027629。

你可能感兴趣的:(监控设备--SDK/ONVIF)