Reputation: 13
I have a kind of a problem which I've suddenly faced with while coding. I use google colab.
The problem is in this line:
img_original1 = cv2.recize(img_original, new_scale, interpolation = cv2.INTER_AREA)
Error message is:
AttributeError: module 'cv2.cv2' has no attribute '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.
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)
Upvotes: 0
Views: 2107
Reputation:
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)
Upvotes: 1