@@ -0,0 +1,1341 @@
+## Change input image to your choosing%0Aimport cv2, numpy as np, pylab%0Aimg = cv2.imread('C:/Users/Colin/Pictures/Screenshots/ss12.png') # Change input image here%0Aimg = cv2.imread('C:/Users/Colin/Pictures/sudoku2.jpg') # Change input image here%0Agray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)%0Agray = cv2.GaussianBlur(gray,(5,5),0)%0Athresh = cv2.adaptiveThreshold(gray,255,1,1,11,2)%0Aim, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)%0Abiggest = None%0Amax_area = 0%0Afor i in contours:%0A        area = cv2.contourArea(i)%0A        if area %3E 100:%0A                peri = cv2.arcLength(i,True)%0A                approx = cv2.approxPolyDP(i,0.02*peri,True)%0A                if area %3E max_area and len(approx)==4:%0A                        biggest = approx%0A                        max_area = area%0A## %5E%5EABOVE%5E%5E http://opencvpython.blogspot.com/2012/06/sudoku-solver-part-2.html%0A                        %0A## vvBELOWvv http://docs.opencv.org/trunk/da/d6e/tutorial_py_geometric_transformations.html                       %0Apts1 = np.float32(biggest)%0Apts2 = np.float32(%5B%5B0,0%5D,%5B0,300%5D,%5B300,300%5D,%5B300,0%5D%5D)%0AM = cv2.getPerspectiveTransform(pts1,pts2)%0Adst = cv2.warpPerspective(img,M,(300,300)) # Output image%0Apylab.subplot(121),pylab.imshow(img),pylab.title('Input')%0Apylab.subplot(122),pylab.imshow(dst),pylab.title('Output')%0Apylab.show()

Add files via upload