Strange image encoding with CamLink

Hello!

I have connected a Canon EOS200D to a CamLink USB stick (Elgato), and I would like to obtain the video stream. The video image acquired by the camera should be correct. Using OBS, the camera image is correctly acquired.

Using OpenCV and Python, the resulting image has a strange encoding. I can not convert it and obtain a standard RGB image.

OBS image: https://user-images.githubusercontent.com/5306860/101246889-4e748780-3716-11eb-8c5b-f93da124b830.png

OpenCV image: https://user-images.githubusercontent.com/5306860/101246802-dd34d480-3715-11eb-8d5d-e1e7ff93270d.png

Steps to reproduce

import cv2
import numpy as np
import matplotlib.pyplot as plt

cap = cv2.VideoCapture(3) # select source (CamLink)

# skip a few images
for i in range(10):
    ret, frame = cap.read() # read image

cap.release()

# display last acquired image
plt.imshow(frame)

Operating system:

  • Ubuntu 18.04 LTS
  • Python 3.7.7
  • OpenCV : 4.4.0

Can somebody help me on this?
Thanks!

opencv uses BGR pixel order for images, while matplotlib expects RGB.

either try to replace the plt.imshow() call with:

cv2.imshow(frame)
cv2.waitKey()

or change the colorspace to RGB:

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
plt.imshow(frame)

in general, mixing several img processing libs will lead to surprises !

1 Like