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

cv2.imshow() complains with: error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage' #167

Closed
matthiasguentert opened this issue Jan 24, 2019 · 9 comments

Comments

@matthiasguentert
Copy link

matthiasguentert commented Jan 24, 2019

Expected behaviour

I was expecting that cv2.imshow() will show the depth image red from openni2 device.

Actual behaviour

When it reaches cv2.imshow("image", img) it crashes with:

Traceback (most recent call last):
File "C:/Dev/Repos/untitled/demo.py", line 28, in
cv2.imshow("image", img)
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1230: error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage'

This seems to be related to this opencv issue which unfortunately got closed. I don't see why.

This is my related post on stackoverflow:

The shape of img is a tuple (480, 640, 3) and dtype is uint16 just before the call to cv2.imshow()

Please note: The same happens when calling

cv2.imshow("test", np.ones((50, 50), dtype=np.uint16));

... so I guess OpenNI can be ruled out... also downgrading to the latest 3.x release (opencv-python 3.4.5.20) made it work!

Steps to reproduce

  • Install opencv-python from pip (version 4.0.0.21)
  • Install openni-2.2.0.post6
  • Run the bellow script on a Windows 10 Pro (x64) machine with Python (3.6.8 - Anaconda)
  • I am using an Orbbec Astra Pro camera which correctly shows up within my device manager as deph sensor and camera as well.
import numpy as np
import cv2
from openni import openni2
from openni import _openni2 as c_api

openni2.initialize("./OpenNI-Windows-x64-2.3/Redist")     

if openni2.is_initialized():
    print('openni2 ready')
else:
    print('openni2 not ready')

dev = openni2.Device.open_any()

depth_stream = dev.create_depth_stream()
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 640, resolutionY = 480, fps = 30))
depth_stream.start()

while(True):
    frame = depth_stream.read_frame()
    frame_data = frame.get_buffer_as_uint16()
    img = np.frombuffer(frame_data, dtype=np.uint16)
    img.shape = (1, 480, 640)
    img = np.concatenate((img, img, img), axis=0)
    img = np.swapaxes(img, 0, 2)
    img = np.swapaxes(img, 0, 1)

    cv2.imshow("image", img)
    cv2.waitKey(25)

depth_stream.stop()
openni2.unload()
@skvark
Copy link
Member

skvark commented Jan 25, 2019

The issue was closed in the upstream because the bug was fixed after 4.0.0 release which means that the fix is included in version 4.0.1. This means that I have to make a release which matches OpenCV 4.0.1.

@skvark skvark closed this as completed Jan 25, 2019
@AlexPeng19
Copy link

@skvark any timeline to release the 4.0.1 version?

@skvark
Copy link
Member

skvark commented Mar 25, 2019

After this PR has been merged (if everything goes fine): #182

Probably later this week given that I have enough free time.

@yzf123456
Copy link

@skvark the 4.0.1 version have released now?

@skvark
Copy link
Member

skvark commented Apr 9, 2019

There is 4.0.1.23 release in PyPI but there were issues with macOS deployment (and with Linux too but that was fixed) so the macOS wheels are missing. I'm about to create a new release which contains also macOS wheels. There will be also 4.1.0 release just after that since it was released yesterday (https://github.com/opencv/opencv/wiki/ChangeLog#version410).

@suzannejb
Copy link

I have this issue with version 4.1.0 (windows). Any thoughts?

@skvark
Copy link
Member

skvark commented Jun 18, 2019

Please report the issue to upstream repo: https://github.com/opencv/opencv/issues. I cannot fix OpenCV bugs here. I think they fixed the bug with Qt & GTK backends, but Windows wheels shipped by this repo use the native Windows backend and it seems to have been only partially fixed: opencv/opencv#13235

@suzannejb
Copy link

thanks!

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

6 participants
@skvark @matthiasguentert @suzannejb @AlexPeng19 @yzf123456 and others