简体   繁体   中英

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. But there is an error when i use opencv python interface to show the image(the os is the mac os):

 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?

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:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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