-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlobDetector.py
57 lines (38 loc) · 1.26 KB
/
BlobDetector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
#!/usr/bin/python
# -*- coding: UTF-8 -*-
Pymiento Project (C) 2017
Autor: Victor Suarez
Blob Detector: Deteccion de Blobs para la tarjeta perforada.
Usa OpenCV.
Version 2.0.0.20170419
'''
import cv2
import numpy as np
from abc import ABCMeta, abstractmethod
# Class BlobDetector: clase base para los detectores( por si se cambia en un futuro).
class BlobDetector:
__metaclass__ = ABCMeta
@abstractmethod
def detect_blobs(self): pass
@abstractmethod
def __init__(self,filename): pass
pass
class PymientoBlobDetector:
imagepath=''
def __init__(self,filename):
self.imagepath=filename
def detect_blobs(self):
# Leemos la imagen de fichero
image = cv2.imread(self.imagepath,cv2.IMREAD_GRAYSCALE)
#hacemos que la imagen ocupe 1/3
imgresized = cv2.resize(image,dsize=(0,0),fx=0.33,fy=0.33)
#imcroped= imgresized[320:50, 480:500]
# Detectamos las formas
detector = cv2.SimpleBlobDetector()
keypoints = detector.detect(imgresized)
#im_with_keypoints = cv2.drawKeypoints(imgresized, keypoints, np.array([]), (0, 0, 255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
#cv2.imshow('test',im_with_keypoints)
#cv2.waitKey(0)
return keypoints
pass