我使用python 2.7和OpenCV将图像设置为全部白色像素,但它不起作用。Python中的OpenCV - 操纵像素
这里是我的代码:
import cv2
import numpy as np
image = cv2.imread("strawberry.jpg") #Load image
imageWidth = image.shape[1] #Get image width
imageHeight = image.shape[0] #Get image height
xPos = 0
yPos = 0
while xPos < imageWidth: #Loop through rows
while yPos < imageHeight: #Loop through collumns
image.itemset((xPos, yPos, 0), 255) #Set B to 255
image.itemset((xPos, yPos, 1), 255) #Set G to 255
image.itemset((xPos, yPos, 2), 255) #Set R to 255
yPos = yPos + 1 #Increment Y position by 1
xPos = xPos + 1 #Increment X position by 1
cv2.imwrite("result.bmp", image) #Write image to file
print "Done"
我使用numpy的设置图像的像素 - 但result.bmp是原始图像的精确副本。
我在做什么错?
编辑:
我知道这是一个坏主意来遍历像素,但什么是我的代码的非功能部分?
谢谢,但什么不在我的代码中工作,我只是将这个例子应用到我正在处理的另一个项目中。对不起,如果我应该更清楚。 – 2015-03-18 22:17:29