Search code examples
python-3.xcameraspiopencvpython

RE: Can OpenCV, Python3 Modules Handle SPI Devices as Cameras?


I am working from these examples online: https://docs.opencv.org/3.4/dd/d43/tutorial_py_video_display.html

I am using a pylepton library in Python also that is located here: https://github.com/groupgets/pylepton. Neither are related but...

  • Does using OpenCV only stay dedicated to USB Cameras in general?
  • And...
  • Can OpenCV understand that I am using a '/dev/spidevX.X' device as a camera?

For instance, I have tried replacing '0' with a '/dev/spidev1.0' device like here...

cap = cv.VideoCapture(0)

like this:

cap = cv.VideoCapture('/dev/spidev1.0')

But...the error relayed via output states that cv.VideoCapture() is looking for an integer only.

I have tried some source exchanging like here:

with Lepton() as l:
    a,_ = l.capture()

    cap = (l.capture('/dev/spidev1.0') == cv.VideoCapture(0))

I know this is incorrect but I figured I would try it to counter some trial and error.


Solution

  • OpenCV is not designed to directly capture from SPI, therefore your code will not work easily. Nevertheless, if you look into capturing a video, try capturing the images and with pylepton and then writing it to a videofile with openCV

    import cv2
    from pylepton import Lepton
    
    running = True
    out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
    with Lepton() as l:
      while running
        a,_ = l.capture()
        out.write(a)
    
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
          break
    out.release()