所以我使用opencv来修改单通道图像上的像素值。 我使用
创建空白图像curr = np.zeros((660,512, 1))
然后执行代码:
for r in regions:
cv2.fillPoly(curr, r, [190])
每个区域看起来像:
[[[363 588]
[304 593]
[323 652]
[377 654]]]
我知道代码至少在某种程度上有效,因为当我使用imshow()时,区域会根据需要填充。但是,我尝试重新访问修改后的像素值,得到[0.]我尝试将整个img ti写成一个临时文件,如下所示:
for elt in curr:
f2.write(str(elt) + '\n')
但是,该文件看起来像
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
[ 0.]
我哪里错了?为什么我不能重新访问我写给图像的190年代?
答案 0 :(得分:1)
工作得很好。
curr = np.zeros((660,512, 1),dtype = np.uint8)
regions = np.array([[[363,588],[304,593],[323,652],[377,654]]])
for r in regions:
cv2.fillPoly(curr, [regions[0]], (190))
# find minimum value, maximum value and their location index in the image
minVal,maxVal,minLoc,maxLoc = cv2.minMaxLoc(curr)
print(maxVal, maxLoc)
答案 1 :(得分:1)