Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv
- filename = "C:\\Users\\ronnieaka\\Desktop\\PROJ\\openCV\\threshed3.jpg"
- image = cv.LoadImage("C:\\Users\\ronnieaka\\Desktop\\PROJ\\openCV\\eyeSnaps\\batch2\\snap3.jpg")
- ##image = cv.LoadImage("C:\\Users\\ronnieaka\\Desktop\\PROJ\\openCV\\eyeSnaps\\closed0.jpg")
- gray = cv.CreateImage((image.width, image.height), 8, 1)
- threshed2 = cv.CreateImage((image.width, image.height), 8, 1)
- canny = cv.CreateImage((image.width, image.height), 8, 1)
- corner = cv.CreateImage((image.width, image.height), 32, 1)
- sobel = cv.CreateImage((image.width, image.height), 32, 1)
- res = cv.CreateImage((canny.width*3,canny.height*3),canny.depth,canny.nChannels)
- def HarrisCorners():
- # Convert color input sobel to grayscale
- cv.CvtColor(image, gray, cv.CV_BGR2GRAY) #========================= 1 gray
- #cv.CornerHarris(gray,corner,3)
- # Equalize the histogram
- cv.EqualizeHist(gray,gray) #======================================= 2 contrast enhancement
- cv.Threshold(gray,threshed2,33,10,cv.CV_THRESH_BINARY) #=========== 3 threshold
- cv.Erode(threshed2,threshed2,None,2)
- cv.EqualizeHist(threshed2,threshed2)
- cv.Dilate(threshed2,threshed2,None,2)
- cv.Sobel(threshed2,sobel,1,2,5)
- cv.Canny(threshed2,canny,20,100,3) #================================ 4 create edges
- cv.Resize(canny,res,cv.CV_INTER_LINEAR)
- ## cv.Sobel(threshed2,sobel,2,2,3)
- cv.CornerHarris(threshed2,corner,3)
- ## cv.CornerHarris(sobel,corner,2)
- max_dist = 0
- maxL = 20
- maxR = 0
- lc =0
- rc =0
- maxLP =[]
- maxRP =[]
- for y in range(0, image.height):
- for x in range(0, image.width):
- harris = cv.Get2D(corner, y, x) # get the x,y value
- # check the corner detector response
- # draw a small circle on the original image
- if harris[0] > 10e-06:
- if ( x<image.width/5 or x>((image.width/4)*3) ) and y>40:
- #cv.Circle(image,(x,y),2,cv.RGB(155, 0, 25))
- if maxL > x:
- maxL = x
- maxLP = (x,y)
- print maxLP
- if maxR < x:
- maxR = x
- maxRP = (x,y)
- dist = maxR-maxL
- if max_dist<dist:
- max_dist = maxR-maxL
- lc = maxLP
- rc = maxRP
- cv.Circle(image,maxLP,3,cv.RGB(0, 255, 0))
- cv.Circle(image,maxRP,3,cv.RGB(0,255,0))
- HarrisCorners()
- while True:
- cv.ShowImage("image",image)
- cv.ShowImage('sobel',res)
- cv.ShowImage("edge",corner)
- cv.ShowImage("threshed", threshed2)
- #cv.ShowImage("pupil",image)
- k = cv.WaitKey(10)
- if k % 0x100 == 27: # if ESC key is pressed....
- #cv.SaveImage(filename,threshed2)
- cv.DestroyWindow("threshed") #Destroy the window of detection results
- cv.DestroyWindow("image")
- cv.DestroyWindow("edge")
- #cv.DestroyWindow("pupil")
- cv.DestroyWindow('sobel')
- print (k%0x100)
- break
- elif k == ord('e'): #if E is pressed
- eyeSnap = "C:\\Users\\ronnieaka\\Desktop\\PROJ\\openCV\\eyeSnaps\\EC_GTSb223.jpg"
- cv.SaveImage(eyeSnap,image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement