我正在读取图像,然后使用 cv2.imshow 显示图像,但是这会使我的脚本在下面的堆栈跟踪中崩溃。
代码
from flask_restful import Resource
from flask import jsonify, request
from .repository import DocumentRepository
import cv2
class DocumentsResource(Resource):
def __init__(self):
self.document_repository = DocumentRepository()
def post(self):
img = cv2.imread('front.jpg')
cv2.imshow('front.jpg', img)
cv2.waitKey(0)
堆栈跟踪
2018-10-23 11:35:09.828 python3[47256:2814041] * +[NSUndoManager _endTopLevelGroupings]、/BuildRoot/Library/Caches/com.apple.xbs /Sources/Foundation/Foundation-1451/Foundation/Misc 中的断言失败.subproj/NSUndoManager.m:361 2018-10-23 11:35:09.830 python3[47256:2814041] *由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“+[NSUndoManager(NSInternal)_endTopLevelGroupings] 只对在主线程上调用。*** 第一次抛出调用堆栈:(0 CoreFoundation 0x00007fff32116fcb __exceptionPreprocess + 171 1 libobjc.A.dylib
0x00007fff58db0c76 objc_exception_throw + 48 2 CoreFoundation
0x00007fff3211cd62 +[NSException raise:format:arguments:] + 98 3
基础 0x00007fff3421b300 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4
基础 0x00007fff341a9e54 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 469 5 AppKit 0x00007fff2f668e56 -[NSApplication run] + 9
0x000000010dc27c12 _ZN26QEventDispatcherMacPrivate22ensureNSAppInitializedEv + 128 7 QtGui 0x000000010dc274ad _ZN19QEventDispatcherMac13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 693 8 QtCore 0x000000010d335d9f _ZN16QCoreApplication13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 81 9 cv2.cpython-37m-darwin.so 0x00000001082677ef cvWaitKey + 207 10 cv2.cpython-37m-darwin.so
0x0000000108267e37 _ZN11GuiReceiver12createWindowE7QStringi + 263 11 cv2.cpython-37m-darwin.so 0x0000000108267c6c cvNamedWindow + 540 12 cv2.cpython-37m-darwin.so 0x000000010826a3a1 _ZN11GuiReceiver9showImageE7QStringPv + 161 13 cv2.cpython-37m-darwin.so 0x000000010826a24c cvShowImage + 572 14 cv2.cpython -37m-darwin.so 0x000000010826298b _ZN2cv6imshowERKNS_6StringERKNS_11_InputArrayE + 475 15 cv2.cpython-37m-darwin.so 0x0000000107853114 _ZL18pyopencv_cv_imshowP7_objectS0_S0_ + 404 16 Python 0x0000000105e2fa4e _PyMethodDef_RawFastCallKeywords + 541 17 Python 0x0000000105e2ef8b _PyCFunction_FastCallKeywords + 44 18 Python
0x0000000105ec7ad7 call_function + 554 19 Python
0x0000000105ebfb57 _PyEval_EvalFrameDefault + 5281 20 Python
0x0000000105e2f379 function_code_fastcall + 117 21 Python
0x0000000105e2fd21 _PyObject_Call_Prepend + 150 22 Python
0x0000000105e2f0a2 PyObject_Call + 137 23 Python
0x0000000105ebfebd _PyEval_EvalFrameDefault + 6151 24 Python
0x0000000105ec83ff _PyEval_EvalCodeWithName + 1747 25 Python
0x0000000105e2eb8a _PyFunction_FastCallDict + 441 26 Python
0x0000000105e2fd21 _PyObject_Call_Prepend + 150 27 Python
0x0000000105e2f0a2 PyObject_Call + 137 28 Python
0x0000000105ebfebd _PyEval_EvalFrameDefault + 6151 29 Python
0x0000000105ec83ff _PyEval_EvalCodeWithName + 1747 30 Python
0x0000000105e2eb8a _PyFunction_FastCallDict + 441 31 Python
0x0000000105ebfebd _PyEval_EvalFrameDefault + 6151 32 Python
0x0000000105ec83ff _PyEval_EvalCodeWithName + 1747 33 Python
0x0000000105e2eb8a _PyFunction_FastCallDict + 441 34 Python
0x0000000105ebfebd _PyEval_EvalFrameDefault + 6151 35 Python
0x0000000105e2f379 function_code_fastcall + 117 36 Python
0x0000000105ec7b42 call_function + 661 37 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 38 Python
0x0000000105e2f379 function_code_fastcall + 117 39 Python
0x0000000105ec7b42 call_function + 661 40 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 41 Python
0x0000000105e2f379 function_code_fastcall + 117 42 Python
0x0000000105ec7b42 call_function + 661 43 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 44 Python
0x0000000105e2f379 function_code_fastcall + 117 45 Python
0x0000000105e2fd21 _PyObject_Call_Prepend + 150 46 Python
0x0000000105e6df5b slot_tp_call + 71 47 Python
0x0000000105e2ede0 _PyObject_FastCallKeywords + 381 48 Python
0x0000000105ec7b3b call_function + 654 49 Python
0x0000000105ebfb57 _PyEval_EvalFrameDefault + 5281 50 Python
0x0000000105e3afe4 gen_send_ex + 242 51 Python
0x0000000105ebf28e _PyEval_EvalFrameDefault + 3032 52 Python
0x0000000105ec83ff _PyEval_EvalCodeWithName + 1747 53 Python
0x0000000105e2ef50 _PyFunction_FastCallKeywords + 225 54 Python
0x0000000105ec7b42 call_function + 661 55 Python
0x0000000105ebfbfd _PyEval_EvalFrameDefault + 5447 56 Python
0x0000000105ec83ff _PyEval_EvalCodeWithName + 1747 57 Python
0x0000000105e2ef50 _PyFunction_FastCallKeywords + 225 58 Python
0x0000000105ec7b42 call_function + 661 59 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 60 Python
0x0000000105e2f379 function_code_fastcall + 117 61 Python
0x0000000105ec7b42 call_function + 661 62 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 63 Python
0x0000000105e2f379 function_code_fastcall + 117 64 Python
0x0000000105ec7b42 call_function + 661 65 Python
0x0000000105ebfb57 _PyEval_EvalFrameDefault + 5281 66 Python
0x0000000105e2f379 function_code_fastcall + 117 67 Python
0x0000000105ec7b42 call_function + 661 68 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 69 Python
0x0000000105e2f379 function_code_fastcall + 117 70 Python
0x0000000105e2fd21 _PyObject_Call_Prepend + 150 71 Python
0x0000000105e6e96f slot_tp_init + 80 72 Python
0x0000000105e6b464 type_call + 178 73 Python
0x0000000105e2ede0 _PyObject_FastCallKeywords + 381 74 Python
0x0000000105ec7b3b call_function + 654 75 Python
0x0000000105ebfb57 _PyEval_EvalFrameDefault + 5281 76 Python
0x0000000105e2f379 function_code_fastcall + 117 77 Python
0x0000000105ec7b42 call_function + 661 78 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 79 Python
0x0000000105e2f379 function_code_fastcall + 117 80 Python
0x0000000105e2fd21 _PyObject_Call_Prepend + 150 81 Python
0x0000000105e2f0a2 PyObject_Call + 137 82 Python
0x0000000105ebfebd _PyEval_EvalFrameDefault + 6151 83 Python
0x0000000105e2f379 function_code_fastcall + 117 84 Python
0x0000000105ec7b42 call_function + 661 85 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 86 Python
0x0000000105e2f379 function_code_fastcall + 117 87 Python
0x0000000105ec7b42 call_function + 661 88 Python
0x0000000105ebfb3e _PyEval_EvalFrameDefault + 5256 89 Python
0x0000000105e2f379 function_code_fastcall + 117 90 Python
0x0000000105e2fd21 _PyObject_Call_Prepend + 150 91 Python
0x0000000105e2f0a2 PyObject_Call + 137 92 Python
0x0000000105f2ecea t_bootstrap + 71 93 libsystem_pthread.dylib
0x00007fff59c2b6c1 _pthread_body + 340 94 libsystem_pthread.dylib
0x00007fff59c2b56d _pthread_body + 0 95 libsystem_pthread.dylib
0x00007fff59c2ac5d thread_start + 13 ) libc++abi.dylib: 以 NSException 类型的未捕获异常终止
操作系统
macOS High Sierra version 10.13.3
架构(例如 x86)
x64
opencv-python 版本
*