Re: [問題] OpenCV addweighted() Error

看板Python作者 (USA~USA)時間9年前 (2016/08/02 17:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
自問自答, 因為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://www.ptt.cc/bbs/Python/M.1470129399.A.88B.html
文章代碼(AID): #1Ne6JtYB (Python)
討論串 (同標題文章)
文章代碼(AID): #1Ne6JtYB (Python)