[英]Mistake : "module cv2.cv2 has no attribute"
I have a kind of a problem which I've suddenly faced with while coding.我在编码时突然遇到了一个问题。 I use google colab.我使用谷歌colab。
The problem is in this line:问题出在这一行:
img_original1 = cv2.recize(img_original, new_scale, interpolation = cv2.INTER_AREA) img_original1 = cv2.recize(img_original, new_scale, 插值 = cv2.INTER_AREA)
Error message is:错误信息是:
AttributeError: module 'cv2.cv2' has no attribute 'recize' AttributeError: 模块 'cv2.cv2' 没有属性 'recize'
How can I solve this problem?我怎么解决这个问题? I tried to add opencv-contrib-python as it was told in similar theme, however, this action didn't help.我尝试添加 opencv-contrib-python,因为它在类似主题中被告知,但是,此操作无济于事。
Here is the code:这是代码:
!pip install opencv-contrib-python
%time
img_original = cv2.imread(fileName, 0)
scale_percentage = 50
width = int(img_original.shape[1]*scale_percentage/100)
height = int(img_original.shape[0]*scale_percentage/100)
new_scale = (width, height)
img_original1 = cv2.recize(img_original, new_scale, interpolation = cv2.INTER_AREA)
cv2_imshow(img_original1)
img_original1.shape
img_original2 = cv2.medianBlur(img_original1, 5)
template = cv2.imread(image_template, 0)
width1, height1 = template.shape[:2]
#Обработка изображения
threshold_image = cv2.adaptiveThreshold(img_original2, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
threshold_template = cv2.adaptiveThreshold(template, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
cv2_imshow(threshold_image)
#Размытие изображения
blurred_image = cv2.GaussianBlur(threshold_image, (31,31), 0)
#Сравнение с оригиналом, порог,
result = cv2.matchTemplate(blurred_image,threshold_template,cv2.TM_CCOEFF_NORMED)
threshold = 0.1
#np.where (condition, [x,y]) при условии(булеан, массив), где True, возвращает значения х или у в зависимости от того, где True
loc = np.where( result >= threshold)
#Цикл где происходит обход изображения по рядам и колоннам по очереди и затем рисуется треугольник в областях, где находится совпадение
for pt in zip(*loc[::-1]):
cv2.rectangle(blurred_image, pt, (pt[0] + width1, pt[1] + height1), (0,0,255), 1)
cv2.imwrite('result.jpg', blurred_image)
cv2_imshow(blurred_image)
cv2_imshow(threshold_template)
cv2_imshow(result)
use as用于
img_original1 = cv2.resize(img_original, new_scale, interpolation = cv2.INTER_AREA)
also, refer this另外,参考这个
import cv2
img = cv2.imread('/path/to/python.png', cv2.IMREAD_UNCHANGED)
print('Original Dimensions : ',img.shape)
scale_percent = 60 # percent of original size
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.