0

Last month I wrote code which utilized threading to acquire images from the raspberry pi camera. Threading appeared to work great as it allowed for fast acquisition but expanding the code to receive queues has been challenging. While looking for help I ran into this thread which outlined the pros and cons of threading. It appeared that while threading works, it has its limitations. This lead me to a post highlighting how to use multiprocessing and opencv to capture and some github code which highlight that multiprocessing is the best method for image aquisition on the raspberry pi.

The problem is many of the code examples available do not appear to work for me. Here is one example I have tried to use. I use spyder to program and this code doesn't show anything when running in the ipython console.

import cv2
import multiprocessing as mp

def camera1():
    global cap1
    cap1 = cv2.VideoCapture(0)    
    while True:
        _, frame1 = cap1.read()
        cv2.imshow('frame1', frame1)

        k = cv2.waitKey(5)
        if k == 27:
            break
    cap1.release()


def cap_images():
    _, img1 = cap1.read()
    cv2.imwrite("Image1.png", img1)


if __name__ == '__main__':
    p1 = mp.Process(target=camera1)
    p1.start()

Trying to run the code through the console results in this error

'multiprocessing' has no attribute 'Process'

Receiving this error is weird as when I import multiprocessing and go through the commands, Process is one of them.

What is a great example of how multiprocessing works? Should I stick with multithreading (given I'm running this on a raspberry pi and one advantage is the low memory footprint)

Hojo.Timberwolf
  • 985
  • 1
  • 11
  • 32

0 Answers0