test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import numpy as np
  2. import cv2
  3. import glob
  4. filename = '1.jpg'
  5. img = cv2.imread(filename)
  6. gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  7. # out1 = cv2.filter2D(gray, -1, np.array(([-1, -2, -1],[0, 0, 0],[1,2,1])))
  8. # opencvOutput = cv2.filter2D(gray, -1, np.array(([-1, 0, 1],[-2, 0, 2],[-1,0,1])))
  9. # cv2.imshow('dst',opencvOutput+out1)
  10. cv2.imshow('dst',img[:,:,0])
  11. cv2.waitKey(0)
  12. cv2.imshow('dst',img[:,:,1])
  13. cv2.waitKey(0)
  14. cv2.imshow('dst',img[:,:,2])
  15. cv2.waitKey(0)
  16. gray = np.float32(gray)
  17. dst = cv2.cornerHarris(gray,2,3,0.04)
  18. #result is dilated for marking the corners, not important
  19. dst = cv2.dilate(dst,None)
  20. # Threshold for an optimal value, it may vary depending on the image.
  21. img[dst>0.01*dst.max()]=[0,0,255]
  22. if cv2.waitKey(0):
  23. cv2.destroyAllWindows()
  24. # # termination criteria
  25. # criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
  26. # # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
  27. # objp = np.zeros((6*7,3), np.float32)
  28. # objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
  29. # # Arrays to store object points and image points from all the images.
  30. # objpoints = [] # 3d point in real world space
  31. # imgpoints = [] # 2d points in image plane.
  32. # images = glob.glob('*.jpg')
  33. # for fname in images:
  34. # img = cv2.imread(fname)
  35. # gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  36. # cv2.imshow('img',img)
  37. # cv2.waitKey(1000)
  38. # # # Find the chess board corners
  39. # # ret, corners = cv2.findChessboardCorners(gray, (7,6),None)
  40. # # # If found, add object points, image points (after refining them)
  41. # # if ret == True:
  42. # # objpoints.append(objp)
  43. # # cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
  44. # # imgpoints.append(corners)
  45. # # # Draw and display the corners
  46. # # cv2.drawChessboardCorners(img, (7,6), corners2,ret)
  47. # # cv2.imshow('img',img)
  48. # # cv2.waitKey(500)
  49. # cv2.destroyAllWindows()