import numpy as np
import numpy as numpy
import cv2
windowsize_r = 8
windowsize_c = 8
img = cv2.imread('image test.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
for r in range(0,gray.shape[0] - windowsize_r, windowsize_r):
for c in range(0,gray.shape[0] - windowsize_c, windowsize_c):
window = gray[r:r+windowsize_r,c:c+windowsize_c]
hist = numpy.histogram(window,bins=256)
k = cv2.waitKey(0)
if k == 27:
cv2.destroyAllWindows()
我试图将am image分成8x8块。我的图片尺寸为320x240。所以最后应该有1200个block.my代码没有显示任何错误,但没有观察到输出。任何人都可以提出更好的解决方案
答案 0 :(得分:0)
在调用waitKey之前,你需要使用cv2.imshow来实际显示补丁。例如:
cv2.imshow('wind',window)
cv2.waitKey(0)