12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import numpy as np
- import cv2
- import glob
- filename = '1.jpg'
- img = cv2.imread(filename)
- gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
- # out1 = cv2.filter2D(gray, -1, np.array(([-1, -2, -1],[0, 0, 0],[1,2,1])))
- # opencvOutput = cv2.filter2D(gray, -1, np.array(([-1, 0, 1],[-2, 0, 2],[-1,0,1])))
- # cv2.imshow('dst',opencvOutput+out1)
- cv2.imshow('dst',img[:,:,0])
- cv2.waitKey(0)
- cv2.imshow('dst',img[:,:,1])
- cv2.waitKey(0)
- cv2.imshow('dst',img[:,:,2])
- cv2.waitKey(0)
- gray = np.float32(gray)
- dst = cv2.cornerHarris(gray,2,3,0.04)
- #result is dilated for marking the corners, not important
- dst = cv2.dilate(dst,None)
- # Threshold for an optimal value, it may vary depending on the image.
- img[dst>0.01*dst.max()]=[0,0,255]
- if cv2.waitKey(0):
- cv2.destroyAllWindows()
- # # termination criteria
- # criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
- # # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
- # objp = np.zeros((6*7,3), np.float32)
- # objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
- # # Arrays to store object points and image points from all the images.
- # objpoints = [] # 3d point in real world space
- # imgpoints = [] # 2d points in image plane.
- # images = glob.glob('*.jpg')
- # for fname in images:
- # img = cv2.imread(fname)
- # gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
- # cv2.imshow('img',img)
- # cv2.waitKey(1000)
- # # # Find the chess board corners
- # # ret, corners = cv2.findChessboardCorners(gray, (7,6),None)
- # # # If found, add object points, image points (after refining them)
- # # if ret == True:
- # # objpoints.append(objp)
- # # cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
- # # imgpoints.append(corners)
- # # # Draw and display the corners
- # # cv2.drawChessboardCorners(img, (7,6), corners2,ret)
- # # cv2.imshow('img',img)
- # # cv2.waitKey(500)
- # cv2.destroyAllWindows()
|