简体   繁体   English

使用cv2.imshow()时发生错误

[英]error occurred when using cv2.imshow()

The task is, i take pictures from the camera, and i process pictures using cnns, and then display the pic with the result. 任务是,我从相机拍摄照片,并使用cnns处理照片,然后显示带有结果的照片。 But there is an error when i use opencv python interface to show the image(the os is the mac os): 但是当我使用opencv python界面显示图像时出现错误(操作系统是mac操作系统):

 while(1):
    test_data = []
    ret, frame = cap.read()
    frame = cv2.imread('hello.jpg')
    h, w, _ = frame.shape
    img = copy.deepcopy(frame)
    img = pre_process(img)
    test_data.append([img])
    ret_res = _infer(inferer, test_data, threshold)
    draw_result(frame, ret_res, h, w)     

    cv2.imshow("hellocapture", frame)

the following error occurred: 发生以下错误:

PC: @                0x0 (unknown)
*** SIGFPE (@0x7fffc5186d01) received by PID 36436 (TID 0x7fffe38773c0) stack 
trace: ***
@     0x7fffdab7bb3a _sigtramp
@     0x7fffc5186d02 CFNumberCreate
@     0x7fffc6c027b5 -[NSPlaceholderNumber initWithDouble:]
@     0x7fffcae3b594 +[CALayer defaultValueForKey:]
@     0x7fffcaebd489 classDescription_locked()
@     0x7fffcaebc9fe classDescription_locked()
@     0x7fffcaebc9fe classDescription_locked()
@     0x7fffcaeb8292 classDescription()
@     0x7fffcaeb8495 CAObject_classInfo
@     0x7fffcae3bdf4 CA::Layer::class_state()
@     0x7fffcae3e081 -[CALayer init]
@     0x7fffc2d07854 -[NSView makeBackingLayer]
@     0x7fffc2d076db -[NSView(NSInternal) _createLayerAndInitialize]
@     0x7fffc2d06d4d -[NSView _doSetWantsLayerYES]
@     0x7fffc2d069da -[NSView setWantsLayer:]
@     0x7fffc2d142b6 __49-[NSThemeFrame _floatTitlebarAndToolbarFromInit:]_block_invoke
@     0x7fffc364b8b6 +[NSAnimationContext runAnimationGroup:]
@     0x7fffc2d13f23 -[NSThemeFrame _floatTitlebarAndToolbarFromInit:]
@     0x7fffc2d11a9c -[NSThemeFrame initWithFrame:styleMask:owner:]
@     0x7fffc2d10522 -[NSWindow _commonInitFrame:styleMask:backing:defer:]
@     0x7fffc2d0ec03 -[NSWindow _initContent:styleMask:backing:defer:contentView:]
@     0x7fffc2d0e65f -[NSWindow initWithContentRect:styleMask:backing:defer:]
@        0x1171ddebd -[QCocoaWindow initWithContentRect:styleMask:backing:defer:]
@        0x1171dddb1 -[NSWindow(QWidgetIntegration) qt_initWithQWidget:contentRect:styleMask:]
@        0x1171cee19 qt_mac_create_window()
@        0x1171ce119 QWidgetPrivate::createWindow_sys()
@        0x1171ce073 qt_mac_window_for()
@        0x1171d3b13 QWidgetPrivate::setModal_sys()
@        0x1172637c8 QWidget::create()
@        0x1175d5431 QToolBarPrivate::init()
@        0x1175d631c QToolBar::QToolBar()
@        0x111ca9c98 CvWindow::createToolBar()
Floating point exception: 8

and i've positioned that the cv2.imshow has the problem, but i don't know how? 并且我已经确定cv2.imshow存在问题,但是我不知道怎么办?

if i just use the folloing code, it's ok 如果我只使用下面的代码,就可以了

#!/usr/bin/env python
# coding=utf-8
import cv2  
import numpy
import matplotlib.pyplot as plot

cap = cv2.VideoCapture(0)
while(1):
    # get a frame
    ret, frame = cap.read()
    # show a frame
    print frame.shape
    cv2.imshow("capture", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
       break

When you display an image in OpenCV you normally need to set a waitKey and release: 在OpenCV中显示图像时,通常需要设置一个waitKey并释放:

while(1):
    test_data = []
    ret, frame = cap.read()
    frame = cv2.imread('hello.jpg')
    h, w, _ = frame.shape
    img = copy.deepcopy(frame)
    img = pre_process(img)
    test_data.append([img])
    ret_res = _infer(inferer, test_data, threshold)
    draw_result(frame, ret_res, h, w)     

    cv2.imshow("hellocapture", frame)
    if cv2.waitKey(1) & 0xFF == ord('q')
        break

cap.release()
cv2.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM