File "test.py", line 32, in <module>
pts1 = np.float32(approx)
NameError: name 'approx' is not defined
Kod: Markera allt
#!/usr/bin/python
# Standard imports
import cv2
import numpy as np;
import math
# Read image
img = cv2.imread("1.jpg",1)
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
lower_board = np.array([0,0,230])
upper_board = np.array([180,255,255])
mask = cv2.inRange(hsv,lower_board, upper_board)
result = cv2.bitwise_and(img,img,mask = mask)
imgray = cv2.cvtColor(result,cv2.COLOR_BGR2GRAY)
im2, contours, hierarchy = cv2.findContours(imgray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for i, contour in enumerate(contours):
area = cv2.contourArea(contour)
if area <= 10000:
continue
epsilon = 0.1*cv2.arcLength(contour,True)
approx = cv2.approxPolyDP(contour,epsilon,True)
cv2.drawContours(img,[approx],0,(0,0,255),2)
print(approx)
pts1 = np.float32(approx)
pts2 = np.float32([[0, 0], [0, 500], [750, 500], [750, 0]])
matrix = cv2.getPerspectiveTransform(pts1, pts2)
warped = cv2.warpPerspective(img, matrix, (750, 500))