{"id":39,"date":"2009-04-09T22:06:44","date_gmt":"2009-04-09T12:06:44","guid":{"rendered":"http:\/\/www.computer-vision-software.com\/blog\/?p=39"},"modified":"2009-11-30T12:58:32","modified_gmt":"2009-11-30T02:58:32","slug":"how-to-get-mjpeg-stream-from-axis-ip-cameras-axis-211m-and-axis-214-ptz-as-camera-device-in-opencv-using-directshow","status":"publish","type":"post","link":"http:\/\/www.computer-vision-software.com\/blog\/2009\/04\/how-to-get-mjpeg-stream-from-axis-ip-cameras-axis-211m-and-axis-214-ptz-as-camera-device-in-opencv-using-directshow\/","title":{"rendered":"Getting MJPEG stream from Axis Ip-camera (Axis 211M and Axis 214 PTZ) as a camera device in OpenCV with DirectShow"},"content":{"rendered":"<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">By default\u00a0OpenCV 1.1 don\u2019t support AXIS ip-cameras. So, this paper describes approach for getting camera interface (cvCaptureFromCAM) from OpenCV when you are using an Axis Ip camera. <\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\"><!--more--><\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">The architecture of OpenCV is set of drivers which allows dynamically get camera interface for currently connected devices to the PC. Particularly, under Windows OpenCV is using VFW (cvcap_vfw.cpp) and DirectShow (cvcap_dshow.cpp) driver.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">The main problem is that AXIS camera cannot be added as VFW device to the system, at least AXIS (<a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/www.axis.com\/');\"  href=\"http:\/\/www.axis.com\/\"><span style=\"color: purple;\">www.axis.com<\/span><\/a>) said that there is driver which can work with Windows Media Encoder only (it is not true, read further). When I installed the driver and tested it via Windows Media Encoder, I had found that there is new DirectShow video source. Since it is known that OpenCV supports Directshow device, I have tried to connect the device to the OpenCV as is. The result was fail deeply in videoInput lib.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">I had downloaded videoInput (\u00a0by Theodore Watson <a onclick=\"javascript:pageTracker._trackPageview('\/mailto\/theo.watson@gmail.com');\"  href=\"mailto:theo.watson@gmail.com\">theo.watson@gmail.com<\/a>) which allows to work with DirectShow devices. This library (OpenCV\\otherlibs\\_graphics\\lib\\videoInput.lib) is used in OpenCV and thus I had found that actually, frame grabber direct show filter cannot get frames due to incorrect frame buffer size\/format.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">I used GraphEdit tool for configuring and trace Axis DirectShow devices and filters. Although, part of properties of AXIS MJPEG Capture Filter hidden inside the filter,\u00a0it can be accessed via GraphEdit and other tools. So, I was able rightly configure filter (set ip address, resolution).\u00a0\u00a0With GraphEdit tool I did catch right interfaces and found AXIS MJPEG Capture Filter ({7BB7689B-1635-498D-9214-6AF9C829D052}). Besides, Axis provided Axis MJPEG Decoder DMO filter ({94297043-BD82-4DFD-B0DE-8177739C6D20}) which allows to convert MJPEG stream to RGB24 stream. I modified code of vidoeinput library to use combination of filters (Axis Capture Filter + Axis MJPEG Decoder DMO filter )\u00a0instead just querying device by getDevice function. I had to add support of MEDIASUBTYPE_MJPG subtype to videoInput library.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">Then I changed highgui library in order to have USB camera priority as first and DirectShow camera as second priority (by default DirectShow was first). Now, it allows to use USB camera and IP camera without rebuilding code.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">After this, all works fine. I can use AXIS IP camera with OpenCV as usual USB device.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">P.S.<\/span><\/p>\n<p style=\"line-height: 12.9pt;\"><span style=\"font-size: 9pt; color: black; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; mso-ansi-language: EN-US;\" lang=\"EN-US\">videoInput\u00a0library has a bug with multithreading, I had to add additional CoInitialize call to setup function in order to work with COM Objects correctly.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default\u00a0OpenCV 1.1 don\u2019t support AXIS ip-cameras. So, this paper describes approach for getting camera interface (cvCaptureFromCAM) from OpenCV when you are using an Axis Ip camera.<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84],"tags":[25,27,26,6],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-opencv","tag-directshow","tag-ipcamera","tag-mjpeg","tag-opencv"],"_links":{"self":[{"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":0,"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.computer-vision-software.com\/blog\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}