python-3.x - 使用索引将图像的一部分从一个复制到另一个时出现openCV错误
问题描述
import cv2
import os
from PIL import Image
img = Image.open('/home/niti/Downloads/ironman.jpeg').convert('RGB')
img=cv2.imread('/home/niti/Downloads/ironman.jpeg')
def click(event,x,y,flag,param):# checking coordiantes
if event==cv2.EVENT_LBUTTONDOWN:
strp=str(x)+','+str(y)
font=cv2.FONT_HERSHEY_COMPLEX
cv2.putText(img,strp,(x,y),font,1,(0,255,255),2)
cv2.imshow('image',img)
b,g,r=cv2.split(img)
img=cv2.merge((b,g,r))
print(img.shape)
print(img.size)
print(img.dtype)
hand=img[928:233, 1103:378]
img[71:121, 187:216]=hand
#cv.imshow('image',img)
cv2.imshow('image',img)
cv2.setMouseCallback('image',click)
cv2.waitKey(0)
cv2.destroyAllWindows()
我收到以下错误
(774, 1280) 990720 uint8 -------------------------------------------------------- -------------------------------- ValueError Traceback (last last call last) in 22 hand=img[928:233, 1103:378] 23 ---> 24 img[71:121, 187:216]=hand 25 26 #cv.imshow('image',img)
ValueError:无法将输入数组从形状(0,0,3)广播到形状(50,29,3)
解决方案
推荐阅读
- php - 如何在常量文件 laravel 中访问 $_SERVER['SERVER_NAME']
- python - pyqt按需加载graphicsspixmapitem
- c# - 在客户端计算机上运行的 Crystal Reports(没有 CRRuntime)
- delphi - 安装 Delphi 包会导致错误丢失 BDS.INI
- ibm-cloud-infrastructure - 如何在 SoftLayer 票证上设置附加设备的密码
- node.js - package-lock.json 会阻止更新吗?
- ruby-on-rails - Ruby on Rails 5 Action Mailer 的错误
- java - 将数据从 kotlin 活动传递到 java DialogFragment
- python - Pandas:使用 python map() 意外输出数据类型
- angular - angular-file-uploader 附加参数