-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
39 lines (33 loc) · 1.26 KB
/
models.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
from sqlalchemy import Column, Integer, Float, ForeignKey, String, LargeBinary
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
import numpy as np
import typing
Base = declarative_base()
class EllipticalParticle(Base):
__tablename__ = "particles"
id = Column(Integer, primary_key=True)
x = Column(Integer)
y = Column(Integer)
a = Column(Float)
b = Column(Float)
theta = Column(Float)
image = relationship('Img', back_populates='particles')
image_id = Column(Integer, ForeignKey("imgs.id"))
occluded = Column(Float)
occlusions = Column(Integer)
def __init__(self, xcenter: int, ycenter: int, a: float, b: float, rotation: float, angle_range: typing.List[typing.Tuple[float, float]]):
self.x = xcenter
self.y = ycenter
self.a = a
self.b = b
self.theta = rotation
self.angle_range = angle_range
self.occlusions = len(angle_range)
self.occluded = 1 - (np.sum([i[1] - i[0] for i in angle_range]) / np.pi / 2)
self.image = None
class Img(Base):
__tablename__ = 'imgs'
id = Column(Integer, primary_key=True)
img_filepath = Column(String)
particles = relationship('EllipticalParticle', back_populates='image')