When I wrote the following Opencv program on Python,
#-*-coding:utf-8-*-
import cv2
import numpy as np
th = 100
# Acquisition of background and input images
im_bg = cv2.imread('kyousitu2.jpeg')
im_in=cv2.imread('kyousitu1.jpeg')
# differential calculation
diff=cv2.absdiff(im_in,im_bg)
# True if the difference is less than the threshold
mask = diff <th
# Height and width of array (image)
height=im_bg.shape[0]
width=im_bg.shape[1]
#resize_img = cv2.resize(img_dst, (high/2, width/2)))
# array generation of the same size as the background image
im_mask=np.zeros(high, width), np.uint8)
# The True part (background) is painted white.
im_mask [mask] = 255
# sesame salt noise removal
im_mask=cv2.medianBlur(im_mask,blur)
# edge detection
im_edge=cv2.Canny(im_mask, 100, 200)
cv2.imshow("detected2.jpg", im_mask)
The following error occurred:
Traceback (most recent call last):
File "sabun7.py", line 22, in <module>
im_mask [mask] = 255
IndexError: too many indications for array
What does this mean?How can I fix it again?
python opencv numpy
shape
in im_mask
is (height, width)
, but shape
in mask
is (height, width,3)
if it is an RGB image, it is shape
.For example, it looks like this
height=im_bg.shape[0]
width=im_bg.shape[1]
channel=im_bg.shape[2]
# array generation of the same size as the background image
im_mask = np.zeros ((hight, width, channel), np.uint 8)
583 PHP ssh2_scp_send fails to send files as intended
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
919 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.