作者PHONm (USA~USA)
看板Python
标题Re: [问题] OpenCV addweighted() Error
时间Tue Aug 2 17:16:37 2016
自问自答,
因为opencv读图建立的矩阵的data type是 uint8
然後numpy 建立的array的data type是 float
所以只要补上一行 img2 = img2.astype(float)
将opencv读图建立的矩阵data type改成float即可。
※ 引述《PHONm (USA~USA)》之铭言:
: opencv手册中 1.3.2 Arithmetic Operations on Images
: 范例
: import cv2
: import numpy as np
: img2 = cv2.imread('opencv_logo.png',1)
: img1 = np.zeros(img2.shape)+100
img2 = img2.astype(float)
: #(书上范例是另一个图,我找不到就开一个大小一样的矩阵)
: dst = cv2.addWeighted(img1,0.3,img2,0.7,0)
: cv2.imshow('dst',dst)
: cv2.waitKey(0)
: cv2.destroyAllWindows()
: 然後会产生下列Error,请问是甚麽原因呢?
: OpenCV Error: Bad argument (When the input arrays in
: add/subtract/multiply/divide functions have different types, the output array
: type must be explicitly specified) in cv::arithm_op, file
: D:\library\opencv3.1\sources\modules\core\src\arithm.cpp, line 663
: Traceback (most recent call last):
: File
: "C:/Users/cash.chien/PycharmProjects/OpenCVParactice/Basic_Operations_on_Images.py",
: line 7, in <module>
: dst = cv2.addWeighted(img1,0.3,img2,0.7,0)
: cv2.error: D:\library\opencv3.1\sources\modules\core\src\arithm.cpp:663:
: error: (-5) When the input arrays in add/subtract/multiply/divide functions
: have different types, the output array type must be explicitly specified in
: function cv::arithm_op
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.124.131.189
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1470129399.A.88B.html