Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread('cebra.jpg', 0)
- im = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
- #gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- #img = cv2.medianBlur(img,5)
- th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
- cv2.THRESH_BINARY,11,2)
- #cv2.imshow('Detector de Lineas', th2)
- th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
- cv2.THRESH_BINARY,11,2)
- #cv2.imshow('Detector de Lineas', th3)
- ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
- #cv2.imshow('Detector de Lineas', thresh1)
- ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
- #cv2.imshow('Detector de Lineas', thresh2)
- ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC+cv2.THRESH_OTSU)
- #cv2.imshow('Detector de Lineas', thresh3)
- ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
- #cv2.imshow('Detector de Lineas', thresh4)
- ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
- #cv2.imshow('Detector de Lineas', thresh5)
- _, contours, h = cv2.findContours(thresh2, 1, 2)
- cv2.drawContours(im, contours, -1, (0, 0, 255), -1 )
- cv2.imshow('Detector de Lineas', im)
- print(len(contours))
- """cnt = contours
- big_contour = []
- max = 0
- cont=0
- for i in cnt:
- #if ((cv2.contourArea(i)) > 10):
- print("Contorno identificado")
- cont += 1
- #if(cont == 1):
- cv2.drawContours(im, i, -1, (0, 0, 255), -1 )
- cv2.imshow('imagen', im)
- #cv2.waitKey()"""
- """edges = cv2.Canny(thresh2, 150, 150, apertureSize = 3)
- lines = cv2.HoughLines(edges, 1, np.pi/180, 80)
- print(lines)
- for line in lines:
- rho, theta = line[0]
- a = np.cos(theta)
- b = np.sin(theta)
- x0 = a*rho
- y0 = b*rho
- x1 = int(x0 + 1000*(-b))
- y1 = int(y0 + 1000*(a))
- x2 = int(x0 - 1000*(-b))
- y2 = int(y0 - 1000*(a))
- cv2.line(img, (x1,y1), (x2,y2), (0, 0, 255), 1, cv2.LINE_AA)"""
- #cv2.imshow('Bordes de Imagen', edges)
- #cv2.imshow('Detector de Lineas', img)
- cv2.waitKey()
- cv2.imwrite("cebra_11.jpg", img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement