cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
var.common.RectSelector Class Reference

Public Member Functions

def __init__ (self, win, callback)
 
def onmouse (self, event, x, y, flags, param)
 
def draw (self, vis)
 
def dragging (self)
 

Public Attributes

 win
 
 callback
 
 drag_start
 
 drag_rect
 

Detailed Description

Definition at line 197 of file common.py.

Constructor & Destructor Documentation

◆ __init__()

def var.common.RectSelector.__init__ (   self,
  win,
  callback 
)

Definition at line 198 of file common.py.

198  def __init__(self, win, callback):
199  self.win = win
200  self.callback = callback
201  cv.setMouseCallback(win, self.onmouse)
202  self.drag_start = None
203  self.drag_rect = None

Member Function Documentation

◆ dragging()

def var.common.RectSelector.dragging (   self)

Definition at line 230 of file common.py.

230  def dragging(self):
231  return self.drag_rect is not None
232 
233 

◆ draw()

def var.common.RectSelector.draw (   self,
  vis 
)

Definition at line 223 of file common.py.

223  def draw(self, vis):
224  if not self.drag_rect:
225  return False
226  x0, y0, x1, y1 = self.drag_rect
227  cv.rectangle(vis, (x0, y0), (x1, y1), (0, 255, 0), 2)
228  return True

◆ onmouse()

def var.common.RectSelector.onmouse (   self,
  event,
  x,
  y,
  flags,
  param 
)

Definition at line 204 of file common.py.

204  def onmouse(self, event, x, y, flags, param):
205  x, y = np.int16([x, y]) # BUG
206  if event == cv.EVENT_LBUTTONDOWN:
207  self.drag_start = (x, y)
208  return
209  if self.drag_start:
210  if flags & cv.EVENT_FLAG_LBUTTON:
211  xo, yo = self.drag_start
212  x0, y0 = np.minimum([xo, yo], [x, y])
213  x1, y1 = np.maximum([xo, yo], [x, y])
214  self.drag_rect = None
215  if x1-x0 > 0 and y1-y0 > 0:
216  self.drag_rect = (x0, y0, x1, y1)
217  else:
218  rect = self.drag_rect
219  self.drag_start = None
220  self.drag_rect = None
221  if rect:
222  self.callback(rect)

Member Data Documentation

◆ callback

var.common.RectSelector.callback

Definition at line 200 of file common.py.

◆ drag_rect

var.common.RectSelector.drag_rect

Definition at line 203 of file common.py.

◆ drag_start

var.common.RectSelector.drag_start

Definition at line 202 of file common.py.

◆ win

var.common.RectSelector.win

Definition at line 199 of file common.py.


The documentation for this class was generated from the following file: