imshow error but imwrite ok in python
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:
import cv2
import numpy as np
if __name__ == "__main__":
img = np.zeros((512,512,3), dtype=np.int)
for j in range(512):
for i in 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()
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 data of img, find that all pixels is [255,255,255]
img = np.zeros((512,512,3), dtype=np.int) <- np.uint8 will behave as expected.
range for an int is [0 .. 2^31], so a value of 255 will look pretty black in imshow().