imshow error but imwrite ok in python
(1)first i new an (512,512,3) zeros array,like this:
Heading ## The function cv2.imshow() display nothing! But cv2.imwrite() write image right way.
- under ubuntu 12.04 LTS
- Edit by sublime text 2
- coding as follows:
bgr import cv2
import numpy as np
if __name__ == "__main__":
img = np.zeros((512,512,3),dtype=np.int)
(2)then i process every pixels like this:
np.zeros((512,512,3), dtype=np.int)
for j in range(512):
`for range(512):
for i in range(512):`
`bgr[i][j][0] = b[0][i][j]`
`bgr[i][j][1] = g[0][i][j]`
`bgr[i][j][2] = r[0][i][j]`
range(512):
img.itemset((i,j,0), 255)
img.itemset((i,j,1), 255)
img.itemset((i,j,1), 255)
#print img
cv2.imshow("test",img)
cv2.imwrite("test.jpg",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
(3)at last i use imshow("image",bgr) to show result:
- cv2.imshow() display an image with all pixels is [0,0,0]
- cv2.imwrite() write an image with all pixels is [255,255,255]
- I just test print the
image.
but there data of img, find that all pixels is nothing (4)at the same time, i use imwrite("image.jpg",bgr),the file writed right.
[255,255,255]