本文整理汇总了Python中SeaGoatVision.commons.param.Param类的典型用法代码示例。如果您正苦于以下问题:Python Param类的具体用法?Python Param怎么用?Python Param使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Param类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExePy1
class ExePy1(Filter):
"""
Python Example Test #1
Convert BGR color to another color.
"""
def __init__(self):
Filter.__init__(self)
self.convert_color = Param("Convert choice", 1, min_v=0, max_v=4)
desc = "0 = original\n1 = BGR TO YUV\n2 = BGR TO HSV\n3 = BGR TO RGB\n\
4 = BGR TO GRAY"
self.convert_color.set_description(desc)
def execute(self, image):
convert_color = self.convert_color.get()
if convert_color == 1:
image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
elif convert_color == 2:
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
elif convert_color == 3:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
elif convert_color == 4:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return image
示例2: __init__
def __init__(self):
Filter.__init__(self)
self.area_min = Param("Area Min", 300, min_v=1, max_v=100000)
self.area_max = Param("Area Max", 35000, min_v=1, max_v=100000)
self._kernel = cv2.getStructuringElement(
cv2.MORPH_RECT, (3, 3), (0, 0))
示例3: ColorThreshold
class ColorThreshold(Filter):
"""Apply a binary threshold on the three channels of the images
Each channel have a minimum and a maximum value.
Everything within this threshold is white (255, 255, 255)
Everything else is black (0, 0, 0)"""
def __init__(self):
Filter.__init__(self)
self.blue = Param("Blue", 20, min_v=1, max_v=256, thres_h=256)
self.green = Param("Green", 20, min_v=1, max_v=256, thres_h=256)
self.red = Param("Red", 20, min_v=1, max_v=256, thres_h=256)
self._barray = None
self._garray = None
self._rarray = None
self.configure()
def configure(self):
min_v, max_v = self.blue.get()
self._barray = np.array([1.0 * (min_v <= x <= max_v)
for x in range(0, 256)], dtype=np.float32)
min_v, max_v = self.green.get()
self._garray = np.array([1.0 * (min_v <= x <= max_v)
for x in range(0, 256)], dtype=np.float32)
min_v, max_v = self.red.get()
self._rarray = np.array([1.0 * (min_v <= x <= max_v)
for x in range(0, 256)], dtype=np.float32)
def execute(self, image):
image[:, :, 0] = image[:, :, 1] = image[:, :, 2] = (
255 * self._barray[image[:, :, 0]] *
self._garray[image[:, :, 1]] *
self._rarray[image[:, :, 2]])
return image
示例4: Morphology
class Morphology(Filter):
def __init__(self):
Filter.__init__(self)
self.kernel_width = Param("Kernel Width", 3, min_v=1, max_v=256)
self.kernel_height = Param("Kernel Height", 3, min_v=1, max_v=256)
self.anchor_x = Param("Anchor X", -1)
self.anchor_y = Param("Anchor Y", -1)
self.iterations = Param("Iteration,", 1, min_v=1)
self.configure()
def configure(self):
self._kernel = cv2.getStructuringElement(cv2.MORPH_RECT,
(self.kernel_width.get(),
self.kernel_height.get()),
(self.anchor_x.get(),
self.anchor_y.get()))
def execute(self, image):
morph = cv2.cvtColor(image, cv.CV_BGR2GRAY)
cv2.morphologyEx(
morph,
cv2.MORPH_CLOSE,
self._kernel,
dst=morph,
iterations=self.iterations.get())
cv2.merge((morph, morph, morph), image)
return image
示例5: __init__
def __init__(self):
Filter.__init__(self)
self.kernel_erode_height = Param(
"Kernel Erode Height",
3,
min_v=1,
max_v=255)
self.kernel_erode_width = Param(
"Kernel Dilate Width",
3,
min_v=1,
max_v=255)
self.kernel_dilate_height = Param(
"Kernel Erode Height",
5,
min_v=1,
max_v=255)
self.kernel_dilate_width = Param(
"Kernel Dilate Width",
5,
min_v=1,
max_v=255)
self.sections = Param("Sections", 5, min_v=1, max_v=10)
self.min_area = Param("Minimum Area", 1000, min_v=1, max_v=65535)
self.configure()
示例6: __init__
def __init__(self):
Filter.__init__(self)
self.kernel_width = Param("Kernel Width", 3, min_v=1, max_v=256)
self.kernel_height = Param("Kernel Height", 3, min_v=1, max_v=256)
self.anchor_x = Param("Anchor X", -1)
self.anchor_y = Param("Anchor Y", -1)
self.iterations = Param("Iteration,", 1, min_v=1)
self.configure()
示例7: __init__
def __init__(self):
Filter.__init__(self)
self.blue = Param("Blue", 20, min_v=1, max_v=256, thres_h=256)
self.green = Param("Green", 20, min_v=1, max_v=256, thres_h=256)
self.red = Param("Red", 20, min_v=1, max_v=256, thres_h=256)
self._barray = None
self._garray = None
self._rarray = None
self.configure()
示例8: LineOrientation
class LineOrientation(Filter):
"""Port of the old line detection code"""
def __init__(self):
Filter.__init__(self)
self.area_min = Param("Area Min", 300, min_v=1, max_v=100000)
self.area_max = Param("Area Max", 35000, min_v=1, max_v=100000)
self._kernel = cv2.getStructuringElement(
cv2.MORPH_RECT, (3, 3), (0, 0))
def execute(self, image):
image_threshold = cv2.split(image)[0]
image_morphology = cv2.morphologyEx(
image_threshold, cv2.MORPH_CLOSE, self._kernel, iterations=1)
contours, _ = cv2.findContours(
image_morphology,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
lines = self.find_lines(contours, image)
self.draw_lines(lines, image)
return image
def draw_lines(self, lines, image):
msg = "LineOrientation: x1=%s x2=%s y1=%s y2=%s \n"
for l, t in lines:
vx, vy, x, y = l
point1 = (x - t * vx, y - t * vy)
point2 = (x + t * vx, y + t * vy)
to_send = msg % (int(point1[0][0]),
int(point1[1][0]),
int(point2[0][0]),
int(point2[1][0]))
self.notify_output_observers(to_send)
cv2.line(image, point1, point2, (0, 0, 255), 3, -1)
cv2.circle(image, (x, y), 5, (0, 255, 0), -1)
self.notify_output_observers("LineOrientation: \n")
def find_lines(self, contours, image):
lines = []
for contour in contours:
approx = cv2.approxPolyDP(contour, 0, False)
area = np.abs(cv2.contourArea(contour))
if self.area_min.get() < area < self.area_max.get():
line_values = cv2.fitLine(approx, cv.CV_DIST_L2, 0, 0.01, 0.01)
rect = cv2.boundingRect(approx)
t = math.sqrt((rect[2] ** 2 + rect[3] ** 2) / 2.0)
lines.append((line_values, t))
cv2.drawContours(image, contour, -1, (255, 255, 0))
return lines
示例9: _deserialize_param
def _deserialize_param(params_ser):
if type(params_ser) is dict:
value = {}
for name, param_ser in params_ser.items():
param = Param(name, None, serialize=param_ser)
value[param.get_name()] = param
return value
elif type(params_ser) is list:
return [Param("temp", None, serialize=param_ser) for param_ser in
params_ser]
return []
示例10: Blur
class Blur(Filter):
"""Smoothes an image using the normalized box filter"""
def __init__(self):
Filter.__init__(self)
self.kernel_width = Param("width", 3, min_v=1, max_v=10)
self.kernel_height = Param("height", 3, min_v=1, max_v=10)
def execute(self, image):
cv2.blur(image, (self.kernel_width.get(),
self.kernel_height.get()),
image)
return image
示例11: Rotate
class Rotate(Filter):
"""Draw a black rectangle on top of the image"""
def __init__(self):
Filter.__init__(self)
self.enable = Param('enable', True)
self.angle = Param('angle', 0, max_v=3, min_v=0)
def execute(self, image):
angle = self.angle.get() * 90
if self.enable.get():
return scipy.ndimage.interpolation.rotate(image, angle)
return image
示例12: Perspective
class Perspective(Filter):
"""Wrap perspective"""
def __init__(self):
Filter.__init__(self)
self.topleftx = Param("Top Left X", 0, min_v=0, max_v=640)
self.toplefty = Param("Top Left TY", 0, min_v=0, max_v=480)
self.bottomleftx = Param("Bottom Left X", 100, min_v=0, max_v=640)
self.bottomlefty = Param("Bottom Left Y", 480, min_v=0, max_v=480)
self.toprightx = Param("Top Right X", 640, min_v=0, max_v=640)
self.toprighty = Param("Top Right Y", 0, min_v=0, max_v=480)
self.bottomrightx = Param("Bottom Right X", 540, min_v=0, max_v=640)
self.bottomrighty = Param("Bottom Right Y", 480, min_v=0, max_v=480)
self.mmat = None
self.configure()
def configure(self):
c1 = np.array([[self.topleftx.get(), self.toplefty.get()],
[self.bottomleftx.get(), self.bottomlefty.get()],
[self.toprightx.get(), self.toprighty.get()],
[self.bottomrightx.get(), self.bottomrighty.get()]],
np.float32)
c2 = np.array([[0, 0], [0, 480], [640, 0], [640, 480]], np.float32)
self.mmat = cv2.getPerspectiveTransform(c2, c1)
def execute(self, image):
cv2.warpPerspective(image, self.mmat, (640, 480), image)
return image
示例13: BilateralFilter
class BilateralFilter(Filter):
"""Applies the bilateral filter to an image."""
def __init__(self):
Filter.__init__(self)
self.diameter = Param("Diameter", 10, min_v=0, max_v=255)
self.sigma_color = Param("Sigma Color", 0, min_v=0, max_v=255)
self.sigma_space = Param("Sigma Space", 0, min_v=0, max_v=255)
def execute(self, image):
return cv2.bilateralFilter(image,
self.diameter.get(),
self.sigma_color.get(),
self.sigma_space.get())
示例14: deserialize
def deserialize(self, data):
if not data:
return False
for uno_data in data:
if not uno_data:
continue
try:
param = Param(None, None, serialize=uno_data)
own_param = self.dct_params.get(param.get_name(), None)
if own_param:
own_param.merge(param)
except Exception as e:
log.printerror_stacktrace(logger, e)
return False
return True
示例15: RemoveObstacle
class RemoveObstacle(Filter):
"""Remove obstacles from an image"""
def __init__(self):
Filter.__init__(self)
self.threshold = Param("Threshold", 12, min_v=0, max_v=255)
#self.vertical_blur = Param("Vertical Blur", 18, min_v=0, max_v=255)
#self.horizontal_blur = Param("Horizontal Blur", 3, min_v=0, max_v=255)
def execute(self, image):
# copy = cv2.cvtColor(image, cv.CV_BGR2HSV)
copy = cv2.blur(image, (3, 3))
h, _, _ = cv2.split(copy)
h[h > self.threshold.get()] = 0
contours, _ = cv2.findContours(
h,
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
x, y, w, h = cv2.boundingRect(contour)
miny = y - h
if miny < 0:
miny = 0
maxy = y + h
if maxy > image.shape[0]:
maxy = image.shape[0]
minx = x
if minx < 0:
minx = 0
maxx = x + w
if maxx > image.shape[1]:
maxx = image.shape[1]
image[miny:maxy, minx:maxx] = 0
return image