typeerror: expected ptr<cv::umat> for argument 'mat'
时间: 2023-06-05 20:47:20 浏览: 1229
这个错误是由于参数mat需要传入cv::umat指针类型,但是实际传入的类型不符合预期,导致类型错误(TypeError)。
可能的原因是你传入的mat参数类型不正确,可能是传入了cv::Mat类型,而不是cv::umat指针类型。你可以检查一下函数的参数类型和传入参数的类型是否一致,以及确认cv::umat指针是否被正确初始化。
相关问题
import qrcode import cv2 import numpy as np from PIL import Image # 要生成二维码的字符串 data = "你好,世界!" # 生成二维码 qr = qrcode.QRCode( version=None, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(data) qr.make(fit=True) qr_img = qr.make_image(fill_color="black", back_color="white") # 将二维码转化为OpenCV格式 qr_img_cv = cv2.cvtColor(np.asarray(qr_img), cv2.COLOR_RGB2BGR) # 打开动态背景图片 cap = cv2.VideoCapture("bg.mp4") # 循环读取视频帧并加入二维码 while True: ret, frame = cap.read() if not ret: break # 将带有二维码的图片缩小并粘贴到视频帧上 qr_img_cv_resized = cv2.resize(qr_img_cv, (200, 200)) frame[100:300, 100:300] = qr_img_cv_resized # 显示视频帧 cv2.imshow("frame", frame) if cv2.waitKey(1) == ord('q'): break # 释放资源 cap.release() cv2.destroyAllWindows()这段代码中报错Traceback (most recent call last): File "D:/Phoenix Robot/python/代码/test1.py", line 21, in <module> qr_img_cv = cv2.cvtColor(np.asarray(qr_img), cv2.COLOR_RGB2BGR) TypeError: Expected Ptr<cv::UMat> for argument '%s'怎么解决
这个错误是因为 `cv2.cvtColor()` 函数的第一个参数需要是一个指向 `cv::UMat` 的指针,但是你传递的是一个 `numpy` 数组。你可以尝试将 `qr_img` 转换为 `cv::UMat` 类型,例如:
```python
qr_img_cv = cv2.cvtColor(cv2.UMat(np.asarray(qr_img)), cv2.COLOR_RGB2BGR)
```
或者直接将 `qr_img` 转换为 `cv::Mat` 类型:
```python
qr_img_cv = cv2.cvtColor(cv2.Mat(np.asarray(qr_img)), cv2.COLOR_RGB2BGR)
```
这样就可以解决这个错误了。
Traceback (most recent call last): File "F:\转换csv\turntocsv.py", line 23, in <module> data = cv2.resize(img_ndarray,(48,48))#图像大小48*48像素值 TypeError: Expected Ptr<cv::UMat> for argument 'src'
这是Python程序运行时的错误提示信息,提示信息中的内容是:在F:\转换csv\turntocsv.py文件的第23行出现了错误,错误类型是cv2.resize()函数的错误,具体错误信息是无法将img_ndarray数组调整为(48,48)大小。
阅读全文
相关推荐
















