multithreading - 如何将图像传递给函数?

标签 multithreading function python-3.x opencv image-processing

这是我使用的代码:

import threading
import cv2

def showimg(*a):
    cv2.imshow('img', a)
    cv2.waitKey(5)
    cv2.destroyAllWindows()

def main():
    img = cv2.imread('tree.jpg')
    t = threading.Thread(target = showimg, args = (img) )
    t.start()

if __name__ == '__main__':
    main()

一个简单的代码,如何将彩色图像传递给函数?

我收到如下错误:

TypeError: mat is not a numerical tuple

我无法理解它。

Q1:我错过了什么?

Q2:彩色图和灰度图一样吗?

最佳答案

我一开始不明白你为什么要使用 import thread

您可以通过相对简单得多的方式将图像传递给函数:

import cv2

def showimg(a):
    cv2.imshow('img', a)

img = cv2.imread('tree.jpg')
showimg(img)

cv2.waitKey(0)

关于multithreading - 如何将图像传递给函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42777740/

相关文章:

c - 函数未在 C 中返回正确的值

python - 在磁盘上存储一个大表,快速检索指定的子集到 np.ndarray

python - 无法使用xpath从某些html元素解析某些信息

C++ WxWidgets : Redirecting Stdout to a wxTextCtrl across mulitple threads

c# - 如何在 .net 中找到当前线程的最大堆栈大小?

java - 有没有办法以编程方式从 JFileChooser.showOpenDialog() 返回?

javascript - 如何将参数传递给函数本身就是参数的函数?

function - 重写一个非 curry 函数haskell

python - 在 python 中打开 .scd 文件?

visual-studio-2008 - VS2008 在遇到断点时暂停所有线程