Answer the question
In order to leave comments, you need to log in
Why doesn't resize (OpenCV) work?
I'm trying to run through the entire image and select a square, n * n in size, which increases each time. But even the smallest square I need to rescale to 64 * 64 pixels in size. When the cycle reaches the resize line, it is simply ignored (at least I don’t see any result of its work).
I learned this by saving the image (looked at its size). In theory, it should be 64 * 64, but it differs from this and is not even in the proportions of a square. What is the reason for this and how to fix it, is there a similar parameter like detectMultiScale, but not for the Haar cascade?
PS By the word "square" I mean getting a fragment of an image in the proportions of a square, the size of which increases.
Here is the code of my program:
import cv2 # подключаем OpenCV
import numpy as np # подключаем numpy
img = cv2.imread("test.jpg") # загрузка изображения
img = np.array(img) # перевод его в массив
for i in range(4, 100): # изменяет размер квадрата с каждым разом
height = np.size(img, 0) # высота изображения
width = np.size(img, 1) # ширина изображения
while heigh % i != 0: # делаем так, чтобы квадратик мог пробежаться по высоте
height = height + 1
while width % i != 0: # делаем так, чтобы квадратик мог пробежаться по ширине
width = width + 1
cv2.resize(img, (width, height)) # переделываем в новое изображение, удобное квадрату
for r in range(0, int(height / i)): # пробег по ширине
for q in range(0, int(width / i)): # по этой ширине создаем квадратик
roi = img[r*i:r*i+i, q*i:q*i+i] # создание квадратика
cv2.imshow("ROI", roi) # для проверки
cv2.resize(roi, (64, 64)) # то, чо не работает
cv2.imwrite("DELETE.jpg", roi) #для проверки
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question