user2684 / imou_life

Home Assistant custom component for controlling Imou devices
MIT License
117 stars 20 forks source link

Can't get usable image via "picUrl" or "thumbUrl" #66

Closed kerryland closed 9 months ago

kerryland commented 1 year ago

Motion-triggered callbacks contain a "picUrl" link to an image (or maybe video?), which I would love to make use of:

trigger:
  platform: webhook
  webhook_id: imou_life_callback_12345
  json:
    deviceType: IPC
    msgType: human
    cname: Driveway
    labelType: humanAlarm
   <snip>
    picUrl:
      - >-
        https://cloudreadproxy-online-sgedge.imoulife.com:27216/6E09A42PAZ645FC_img/Alarm/0/3d42f60f6e1e4427b549290b33e52630_big_0_thumb_qcif.dav?sig=jgmqNtLj9/qbVWP9ckTBT6wSfNoai1rf09GsmXerliQ=&e=1688518125&v=v1&t=r&time=20230704004845

...but it appears to be a ".dav" file, and I can't find a way to turn that into anything useful (jpeg or png or mp4 -- anything!)

The human-detection isn't very good in the rain, so I want to send the image to deepstack for some higher quality analysis. Currently I am making a call to the generic "camera.snapshot" method, but it fires a few seconds after motion is detected, so is often too late to see anything :-(

Any ideas on how to access this image?

user2684 commented 1 year ago

Correct, it is a dav file. Actually should be an encypted dav file from my understanding. I've looked around for dav -> mpg converter in the past but apart from some online utilities I'm not sure there is something already part of HA which can do the conversion. To be investigated for sure

user2684 commented 9 months ago

closing for now since looks like too complicated and requiring dependencies not available by default on HA

bmabir17 commented 5 months ago

I also tried to save the image from the url found in picurlArray from https://open.imoulife.com/book/http/device/alarm/getAlarmMessage.html

async def download_image(session, url, filename):
  async with session.get(url) as response:
    if response.status == 200:
      data = await response.read()
      print(f"Downloaded data size: {len(data)} bytes")
      # Use frombuffer instead of fromstring (handling DeprecationWarning)
      img_np = np.frombuffer(data, dtype=np.uint8)  
      try:
          # Check if data is not empty before saving with OpenCV
          if np.any(img_np):
            # Decode the image with OpenCV to capture correct dimensions
           img = cv2.imdecode(img_np, cv2.IMREAD_UNCHANGED)  # Use cv2.IMREAD_COLOR for color images

            # Save with corrected dimensions
            if img:
                cv2.imwrite(filename, img)
                print(f"Image saved: {filename}")
            else:
               print("image is empty in cv2")
          else:
              print(f"Downloaded image data is empty for {url}, skipping save.")
      except Exception as e:
          print(f"Error saving image: {url} ({e})")
    else:
      print(f"Error downloading image: {url} (status: {response.status})")

But the image that i am getting saved has width of 1 pixel and height of 35319 pixel. But when i try to use cv2.imdecode(img_np, cv2.IMREAD_UNCHANGED) as shown above, it gets cv2 decoded image as empty.