-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathPixelObj.py
51 lines (46 loc) · 1.38 KB
/
PixelObj.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
from FCab import JsonDump
import math
import string
# - - - - - - - - - - - - - - - -
# - - - - PIXELOBJ CLASS - - - -
# - - - - - - - - - - - - - - - -
class PixelObj:
def __init__(self, id_):
self.XYset = set()
self.id_ = id_
self.numberOfPixels = 0
self.coord_x = 0
self.coord_y = 0
self.coord_real_y = 0
print "new object made with id: ", self.id_
def checkXYset(self, nList):
flag = False
for entry in nList:
if len(self.XYset) is 0:
print "append"
self.XYset.add(entry)
if entry in self.XYset:
flag = True
if flag is True:
for entry in nList:
self.XYset.add(entry)
return flag
def countPixel(self):
self.numberOfPixels = len(self.XYset)
print "Object ID: ", self.id_
print "Number of Pixels: ", self.numberOfPixels
def computeMeanCoord(self):
if len(self.XYset) is 0:
return
tmpX = 0
tmpY = 0
for ent in self.XYset:
x, y = ent
tmpX += x
tmpY += y
self.coord_x = int(tmpX / len(self.XYset))
tmp = int(tmpY / len(self.XYset))
self.coord_real_y = tmp
self.coord_y = 96 - tmp
print "X coord: ", self.coord_x
print "Y coord: ", self.coord_y