Friday, May 6, 2016

HoW To ImPoRt ImAgE In OpEnCV PyThOn

No comments
first step we need understand whenever program start we should import opencv to python libary so that we use
   import cv2
import numpy  for numerical operations
   import numpy as np
In here we need to  three process for import and show image
  • import image(cv2.imread)
  • show image(cv2.imshow)
  • save image(cv2.imwrite)

first lets we know how to import image

#import numerical operation
import numpy as np
#import opencv
import cv2
#read image from loction where we have.then assign name as jaga.
jaga = cv2.imread('/home/jagadish/Downloads/Baby_Face.JPG',cv2.IMREAD_COLOR)
#now we need to disply imaage in normal size or auto size otherwise that will display larger
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
#show image(jaga) in window(image)as we can assign window name
cv2.imshow('image',jaga)
#wait key used for stop opertion when we press zero
cv2.waitKey(0)
#to close all windows
cv2.destroyAllWindows()
import methods
 cv2.IMREAD_COLOR- read color image
cv2.IMREAD_GRAYSCALE-read in grayscale
cv2.IMREAD_UNCHANGED-read in alpha channel OR normal colors

only changing formation is
jaga = cv2.imread('/home/jagadish/Downloads/Baby_Face.JPG',cv2.IMREAD_COLOR)
jaga = cv2.imread('/home/jagadish/Downloads/Baby_Face.JPG',cv2.IMREAD_GRAYSCALE)
jaga = cv2.imread('/home/jagadish/Downloads/Baby_Face.JPG',cv2.IMREAD_UNCHANGED)



i had tested in my laptop.im sure this will work for you

No comments :

Post a Comment