title: take .jpg snapshots from IP camera with a python script
body: <p>I want to take a picture every determined time from my local IP camera conected directly to my computer, no router, no nothing, just my IP camera connected through a network cable to my computer. I'm able to see my IP camera on the mozilla firefox browser by just typing its IP address and logging in, also I'm able to get snapshots from there by clicking on the snapshot button on the web interface. What I want to do is to make a python script that takes snapshots from this IP cam (every 10 seconds, for example). I have tried this script:</p>
  
  <pre><code>import base64
  import time
  import urllib2
  
  import cv2
  import numpy as np
  
  class ipCamera(object):
  
      def __init__(self, url, user=None, password=None):
          self.url = url
          auth_encoded = base64.encodestring('%s:%s' % (user, password))[:-1]
          self.req = urllib2.Request(self.url)
          self.req.add_header('Authorization', 'Basic %s' % auth_encoded)
  
      def get_frame(self):
          response = urllib2.urlopen(self.req)
          img_array = np.asarray(bytearray(response.read()), dtype=np.uint8)
          frame = cv2.imdecode(img_array, 1)
          return frame
  
  camaraIP = ipCamera('http://IPaddress/snapshot','username','password')
  imagen_tomada=camaraIP.get_frame()
  file = "IPimage.jpg"
  cv2.imwrite(file, imagen_tomada)
  </code></pre>
  
  <p>with a Tenvis IP camera and it worked fine, because with this brand of IP cameras (Tenvis) whenever you take a snpashot it automatically opens a new browser tab with "snapshot" at the end of the URL, so that's the URL I pass to the program and it works fine, it can capture the image in .jpg format perfectly.... But the type of camera I am using right now is a DAHUA IP camera and it doesn't open another browser tab when I push the snapshot button, instead it opens my windows image viewer and shows me the picture and saves it into my computer with a .bmp format. So if anybody could help me please, I did a lot of research about this with no results, I'm working with python 2.7, OpenCv version 3.0, I have installed PIL and PILLOW, I'm on a 64 bit windows 10 machine and the brand of the camera, as I mentioned before, is a Dahua IP camera, the model of the camera is DH-IPC-HFW1105SN-0360B. Thanks a lot for your time, I really appreciate your help beforehand.</p>