gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:14:21 25 4
gpt4 key购买 nike

这是我使用的代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com