4

I'm trying to export the data coming from a thermal camera but I get an error message that says

error: /build/opencv-ISmtkH/opencv-2.4.9.1+dfsg/modules/highgui/src/cap_ffmpeg.cpp:238: error: (-215) image->depth == 8 in function writeFrame

Can someone look at what I'm doing and tell me what I'm doing wrong? I followed and example pretty closely so I don't understand what this error means or why it's happening.

o = camera.add_overlay(np.getbuffer(a), size=(320,240), layer=3, alpha=int(alpha), crop=(0,0,80,60), vflip=flip_v)

filename = time.strftime("%Y.%m.%d  %H.%M.%S", time.localtime()) + ".avi"
fourcc =  cv2.cv.CV_FOURCC('I','4','2','0')
out = cv2.VideoWriter(filename, fourcc, fps, (width, height))

try:
  time.sleep(0.2) # give the overlay buffers a chance to initialize
  with Lepton(device) as l:
    last_nr = 0
    while True:
      _,nr = l.capture(lepton_buf)

      out.write(lepton_buf)

      if nr == last_nr:
        # no need to redo this frame
        continue
      last_nr = nr
      cv2.normalize(lepton_buf, lepton_buf, 0, 65535, cv2.NORM_MINMAX)
      np.right_shift(lepton_buf, 8, lepton_buf)
      a[:lepton_buf.shape[0], :lepton_buf.shape[1], :] = lepton_buf
      o.update(np.getbuffer(a))
except Exception:
  traceback.print_exc()
finally:
  camera.remove_overlay(o)
Angel Lockhart
  • 157
  • 1
  • 2
  • 11

2 Answers2

7

You need to change out.write(lepton_buf) to out.write(np.uint8(lepton_buf))

What you're trying to write isn't a number and that's what's confusing it.

sgmm
  • 580
  • 2
  • 7
  • 13
1

Several suggestions to try

Try a more common codec:

fourcc=cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')

make sure your video dimensions fit the image dimensions. Try swapping width and height, the order of these can be confusing.

height,width,channels=lepton_buf.shape

or specify directly width and height for your video:

out = cv2.VideoWriter(filename, fourcc, 8.0, (60, 80))

as stated before by @Crystal, make sure you convert your image data to data type 'uint8'

Try saving to a 'fresh' file name. Sometimes opencv videowriter silently fails saving to a file that hasn't been properly released from a previous access.

finally, release your file when done writing frames!

out.release()
jlarsch
  • 2,217
  • 4
  • 22
  • 44
  • Thank you. I tried the first suggest and it gave me a module error so I think I'm going to stick with the codec I have now. Also do you know if there is a way to confirm what the height and width of the video is? The datahsheet tells me the resolution is 80x60 but since I'm using someone else code to run the camera I wanted to make sure that my numbers were correct. – Angel Lockhart Aug 11 '16 at 14:48
  • What system are you using? I am surprised xvid would not be available in your opencv/ffmpeg. Have you ever successfully saved any video via opencv on your computer? – jlarsch Aug 11 '16 at 18:58
  • your code specifies `out = cv2.VideoWriter(filename, fourcc, fps, (width, height))` . Where do you specify width and height? – jlarsch Aug 12 '16 at 21:50
  • check the format of your video data using `print lepton_buf.shape()` before your statement `out.write(lepton_buf)` . This will print for each frame and will also be a sanity check that frames are coming from your camera at all. – jlarsch Aug 12 '16 at 21:54
  • try `out = cv2.VideoWriter(filename, fourcc, 8.0, (60, 80))` instead – jlarsch Aug 12 '16 at 22:05
  • I ran into a similar issue and @AngelLockhart's suggestion to swap the width and height worked for me. – Tom Johnson Apr 05 '18 at 08:02