opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
77.61k stars 55.71k forks source link

cv2.imshow() freeze inside loop in Ubuntu 18.04 with Conda #19945

Open JVedant opened 3 years ago

JVedant commented 3 years ago
System information (version)
Detailed description

When used cv2.imshow() in loop, the window doesn't reload and gets stuck at the first frame.

Steps to reproduce
```.py
def process_img(data):
      i = np.array(data.raw_data)
      i2 = i.reshape((IM_HEIGHT, IM_WIDTH, 4))
      i3 = i2[:, :, :3]
      cv2.imshow("Dashcam", i3)
      cv2.waitKey(1)
      return i3/255.0
```

the function block is used in a loop of multiple images where it is suppose to display all the images in a single window.

alalek commented 3 years ago

Please provide stack trace (from gdb) and used modules.

Does it work with normal numpy arrays without of this processing:

      i = np.array(data.raw_data)
      i2 = i.reshape((IM_HEIGHT, IM_WIDTH, 4))
      i3 = i2[:, :, :3]

Please try to run OpenCV samples (e.g. https://github.com/opencv/opencv/blob/master/samples/python/drawing.py).

JVedant commented 3 years ago

Please provide stack trace (from gdb) and used modules.

Does it work with normal numpy arrays without of this processing:

      i = np.array(data.raw_data)
      i2 = i.reshape((IM_HEIGHT, IM_WIDTH, 4))
      i3 = i2[:, :, :3]

Please try to run OpenCV samples (e.g. https://github.com/opencv/opencv/blob/master/samples/python/drawing.py).

The code block is used in carla (simulator to train Reinforcement Learning models on self driving cars), and the function arguement "data" is captured from one of the sensors of the vehicle. (using carla.listen() - https://carla.readthedocs.io/en/latest/python_api/#methods_41)

Yes it does works with the provided OpenCV Sample, but not with the numpy preprocessing (converting raw data to array, reshaping and then slicing). Also when added print(i3) in the function, the values of i3 are displayed perfectly in the terminal.

alalek commented 3 years ago

"Slicing" of numpy arrays is not properly supported by OpenCV Python binding. see #15895 for problem statement and workarounds

JVedant commented 3 years ago

Ohh, so how shall one display a image from bytes ? because the "data.rawa_data" returns bytes value and the 4th dimension is not required so i need to slice the array into 3 dimension. also i guess it worked on some older versions.