Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pikrellcam stream can't be used with cv2 due to missing channels for cvtColor #64

Open
fotisK69 opened this issue Aug 26, 2020 · 0 comments

Comments

@fotisK69
Copy link

Hi,

I am trying to get the stream from my pi camera using pikrellcam and read it via cv2 python module, but it seems that the stream can't be handled correctly because the cvtColor is complaining:

Traceback (most recent call last):
  File "...\Python\Python38\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "...\Python\Python38\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "...\Python\Python38\lib\multiprocessing\pool.py", line 109, in worker
    initializer(*initargs)
  File "...\fotisK69\dev\object_detector_app-master\object_detection_app.py", line 85, in worker
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

The stream it self works on a browser, so I do get the camera stream to my laptop!
My setup is using 4 raspberry pi's zero w + pi camera (on each pi) and since the zero is not very strong in object detection due lack of cpu/gpu resources to do this on a laptop for 4 different camera streams.

The below code snippet is reading the stream overlaying some text and writing to a new file and show it in a window:

    print('Reading from webcam.')
    video_capture = WebcamVideoStream(src="http://<ip>:<port>",
                                      width=640,
                                      height=480).start()

    frame_width = 640
    frame_height = 480
    out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height))
    
    while True:
        frame = video_capture.read()
        input_q.put(frame)

        output_rgb = cv2.cvtColor(output_q.get(), cv2.COLOR_RGB2BGR)
        cv2.putText(output_rgb, "CPU=", (10, frame_height - 10), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0, 0), 1, cv2.LINE_AA)
        out.write(output_rgb)
        cv2.imshow('Video', output_rgb)

I know that i can overlay text with pikrellcam too but the will not be related to each pi zero but should add other information. This is just an example.

I guess I have to configure pikrellcam do get a different stream quality, but I am just starting using pikrellcam.
I was trying a different module like motion with the same pi camera and the stream what that solution was working with cv2.

Can you help please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant