如何修复操作既不是Array OP Array'在图像中添加水印时
我是OpenCV和Python的新手。我正在尝试将水印添加到图像中,并遵循此YouTube教程: https://www.youtube.com/watch?v=zbj3ey4s9r8
这是我遇到的错误:
trackback(最近的最新通话):文件 “ c:\ user \ user \ desktop \ watermark \ watermark3.py”,第27行, 结果= cv2.AddWeighted(ROI,1,徽标,0.3,0)cv2.error:OpenCV(4.5.5) D:\ a \ opencv-python \ opencv-python \ opencv \ modules \ core \ src \ src \ arithm.cpp:650: 错误:(-209:输入参数的大小不匹配)操作是 两者都不是“数组OP数组”(其中数组的大小相同且相同 频道的数量),也不是“ Array OP标量”,也不是“标量OP数组” 函数'cv :: arithm_op'
我认为我遵循视频中相同的指示:
import cv2
import numpy as np
import glob
import os
logo = cv2.imread("images/testlogo2.png")
h_logo, w_logo, _=logo.shape
print(h_logo, w_logo)
images_path = glob.glob("C:/Users/User/Desktop/testimage/*.*")
#deciding the position of the logo
for img_path in images_path:
img = cv2.imread(img_path)
h_img, w_img, _=img.shape
print(h_img, w_img)
center_x = int(w_img/2)
center_y = int(h_img/2)
top_y=center_y+int(h_logo/2)
left_x=center_x+int(w_logo/2)
bottom_y=h_logo+top_y
right_x=w_logo+left_x
#roi
roi = img[top_y:bottom_y, left_x:right_x]
# Add the Logo to the Roi
result = cv2.addWeighted(roi,1,logo,0.3,0)
# Replace the ROI on the image
img[top_y: bottom_y, left_x: right_x] = result
# Get filename and save the image
filename = os.path.basename(img_path)
cv2.imwrite("C:/Users/User/Desktop/testimage/new/logo_"+filename,img)
print("Watermark added to al the images")
I'm new to OpenCV and Python. I'm trying to add watermark to an image and have been following this Youtube tutorial:
https://www.youtube.com/watch?v=zbJ3EY4s9r8
This is the error that I get:
Traceback (most recent call last): File
"C:\Users\User\Desktop\watermark\watermark3.py", line 27, in
result = cv2.addWeighted(roi,1,logo,0.3,0) cv2.error: OpenCV(4.5.5)
D:\a\opencv-python\opencv-python\opencv\modules\core\src\arithm.cpp:650:
error: (-209:Sizes of input arguments do not match) The operation is
neither 'array op array' (where arrays have the same size and the same
number of channels), nor 'array op scalar', nor 'scalar op array' in
function 'cv::arithm_op'
I think I have followed the same instruction from the video:
import cv2
import numpy as np
import glob
import os
logo = cv2.imread("images/testlogo2.png")
h_logo, w_logo, _=logo.shape
print(h_logo, w_logo)
images_path = glob.glob("C:/Users/User/Desktop/testimage/*.*")
#deciding the position of the logo
for img_path in images_path:
img = cv2.imread(img_path)
h_img, w_img, _=img.shape
print(h_img, w_img)
center_x = int(w_img/2)
center_y = int(h_img/2)
top_y=center_y+int(h_logo/2)
left_x=center_x+int(w_logo/2)
bottom_y=h_logo+top_y
right_x=w_logo+left_x
#roi
roi = img[top_y:bottom_y, left_x:right_x]
# Add the Logo to the Roi
result = cv2.addWeighted(roi,1,logo,0.3,0)
# Replace the ROI on the image
img[top_y: bottom_y, left_x: right_x] = result
# Get filename and save the image
filename = os.path.basename(img_path)
cv2.imwrite("C:/Users/User/Desktop/testimage/new/logo_"+filename,img)
print("Watermark added to al the images")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论