本文整理汇总了Python中SeaGoatVision.commons.param.Param.get方法的典型用法代码示例。如果您正苦于以下问题:Python Param.get方法的具体用法?Python Param.get怎么用?Python Param.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SeaGoatVision.commons.param.Param
的用法示例。
在下文中一共展示了Param.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Morphology
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例2: ColorThreshold
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例3: LineOrientation
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例4: Blur
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例5: Rotate
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例6: BilateralFilter
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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())
示例7: Perspective
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例8: RemoveObstacle
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例9: Canny
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
class Canny(Filter):
"""Apply a canny filter to the image"""
def __init__(self):
Filter.__init__(self)
self.threshold1 = Param("Threshold1", 10, min_v=0, max_v=255)
self.threshold2 = Param("Threshold2", 100, min_v=0, max_v=255)
def execute(self, image):
gray = cv2.cvtColor(image, cv.CV_BGR2GRAY)
cv2.Canny(gray, self.threshold1.get(), self.threshold2.get(), gray)
cv2.merge((gray, gray, gray), image)
return image
示例10: ExePy1
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
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
示例11: Rectangle
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
class Rectangle(Filter):
"""Draw a black rectangle on top of the image"""
def __init__(self):
Filter.__init__(self)
self.x1 = Param('x1', 0, max_v=65535, min_v=0)
self.y1 = Param('y1', 0, max_v=65535, min_v=0)
self.x2 = Param('x2', 100, max_v=65535, min_v=0)
self.y2 = Param('y2', 100, max_v=65535, min_v=0)
def execute(self, image):
cv2.rectangle(image,
(self.x1.get(), self.y1.get()),
(self.x2.get(), self.y2.get()),
(0, 0, 0),
cv2.cv.CV_FILLED)
return image
示例12: GaussianBlur
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
class GaussianBlur(Filter):
"""Smoothes an image using a Gaussian filter"""
def __init__(self):
Filter.__init__(self)
self.kernel_height = Param("Kernel Height", 3, min_v=1, max_v=256)
self.kernel_width = Param("Kernel Width", 3, min_v=1, max_v=256)
self.sigma_x = Param("Sigma X", 3, min_v=1, max_v=256)
self.sigma_y = Param("Sigma Y", 3, min_v=1, max_v=256)
def execute(self, image):
cv2.GaussianBlur(image,
(self.kernel_height.get(),
self.kernel_width.get()),
sigmaX=self.sigma_x.get(),
sigmaY=self.sigma_y.get(),
dst=image)
return image
示例13: RemoveGrass
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
class RemoveGrass(Filter):
"""Remove grass from an image"""
def __init__(self):
Filter.__init__(self)
self.threshold = Param("Threshold", 100, min_v=0, max_v=255)
self.technique = Param("Technique", 0, min_v=0, max_v=2)
def remove_green_from_blue(self, image):
blue, green, red = cv2.split(image)
new_blue = blue - green / 2
black = blue < new_blue
new_blue[black] = 0
threshold = new_blue < self.threshold.get()
blue[threshold] = 0
green[threshold] = 0
red[threshold] = 0
cv2.merge((blue, green, red), image)
return image
def add_green_to_blue(self, image):
blue, green, red = cv2.split(image)
new_color = green + blue
white = ((new_color < green) & (new_color < blue))
new_color[white] = 255
threshold = new_color > self.threshold.get()
blue[threshold] = 0
green[threshold] = 0
red[threshold] = 0
cv2.merge((blue, green, red), image)
return image
def enhance_grass(self, image):
blue, green, _ = cv2.split(image)
image[:, :, 0] = np.subtract(blue, green / 2)
return image
def execute(self, image):
if self.technique.get() == 0:
return self.add_green_to_blue(image)
elif self.technique.get() == 1:
return self.remove_green_from_blue(image)
elif self.technique.get() == 2:
return self.enhance_grass(image)
示例14: FaceDetection
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
class FaceDetection(Filter):
"""Detect faces and eyes"""
def __init__(self):
Filter.__init__(self)
self.nb_face = 1
# linux path
path_frontal_face = os.path.join('/', 'usr', 'share', 'opencv',
'haarcascades',
'haarcascade_frontalface_alt.xml')
self.face_detect_name = os.path.join(
'data', 'facedetect', path_frontal_face)
self.face_cascade = cv2.CascadeClassifier()
self.face_cascade.load(self.face_detect_name)
self.notify_filter = Param("notify", False)
def execute(self, image):
gray = cv2.cvtColor(image, cv.CV_BGR2GRAY)
cv2.equalizeHist(gray, gray)
faces = self.face_cascade.detectMultiScale(gray,
1.1,
2,
0 | cv.CV_HAAR_SCALE_IMAGE,
(30, 30))
for face in faces:
self.draw_rectangle(image, face, (0, 0, 255))
return image
def draw_rectangle(self, image, coord, color):
x, y, w, h = coord
miny = y
if miny < 0:
miny = 0
max_y = y + h
if max_y > image.shape[0]:
max_y = image.shape[0]
minx = x
if minx < 0:
minx = 0
max_x = x + w
if max_x > image.shape[1]:
max_x = image.shape[1]
cv2.rectangle(image, (minx, miny), (max_x, max_y), color, 3)
c_x = (max_x - minx) / 2 + minx
c_y = (max_y - miny) / 2 + miny
if self.notify_filter.get():
self.notify_output_observers("facedetect%d : x=%d, y=%d" %
(self.nb_face, c_x, c_y))
self.nb_face += 1
return image[miny:max_y, minx:max_x]
示例15: ColorLevel
# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import get [as 别名]
class ColorLevel(Filter):
"""Determine the value in % a color will have.
0% = Nothing
50% = Half the original value.
100% = Original
Example: With 50% Blue and the following pixel (100, 100, 100) give (50, 100, 100)"""
def __init__(self):
Filter.__init__(self)
self.red = Param("red", 100, min_v=0, max_v=255)
self.green = Param("green", 100, min_v=0, max_v=255)
self.blue = Param("blue", 100, min_v=0, max_v=255)
def execute(self, image):
if self.red != 100:
image[:, :, 2] *= self.red.get() / 100
if self.green != 100:
image[:, :, 1] *= self.green.get() / 100
if self.blue != 100:
image[:, :, 0] *= self.blue.get() / 100
return image