示例#1
0
 def Open(self):
     self.track_len = 10
     self.detect_interval = 5
     self.tracks = []
     self.frame_idx = 0
     print(__doc__)
     PyStreamRun(self.OpenCVCode, titleWindow)
示例#2
0
 def Open(self):
     self.selectWindow = (0, 0, 0, 0)
     self.track_window = None
     self.drag_start = None
     self.initialized = False
     self.show_backproj = False
     self.hist = None
     PyStreamRun(self.OpenCVCode, titleWindow)
示例#3
0
    def Open(self):
        self.frame = None
        self.paused = False
        self.tracker = PlaneTracker()

        cv.namedWindow(titleWindow)
        self.rect_sel = common.RectSelector(titleWindow, self.on_rect)
        PyStreamRun(self.OpenCVCode, titleWindow)
    def Open(self):
        self.imgRGB = None
        self.paused = False
        self.tracker = PlaneTracker()

        cv.namedWindow(titleWindow)
        cv.createTrackbar('focal', titleWindow, 25, 50, common.nothing)
        self.rect_sel = common.RectSelector(titleWindow, self.on_rect)
        PyStreamRun(self.OpenCVCode, titleWindow)
示例#5
0
    def Open(self):
        cv.namedWindow('camshift - Draw below to start or restart tracking')
        cv.setMouseCallback(
            'camshift - Draw below to start or restart tracking', self.onmouse)

        self.selection = None
        self.drag_start = None
        self.show_backproj = False
        self.track_window = None
        self.initialized = False
        self.both = None
        self.imgRGB = None
        self.img = None
        print(__doc__)
        PyStreamRun(self.OpenCVCode, titleWindow)
示例#6
0
    def Open(self):
        cv.namedWindow('camshift')
        cv.setMouseCallback('camshift', self.onmouse)

        self.selection = None
        self.drag_start = None
        self.show_backproj = False
        self.track_window = None
        self.initialized = False
        self.both = None
        self.vis = None
        self.img = None
        print(__doc__)
        from PyStream import PyStreamRun
        PyStreamRun(self.run, 'PyStream_Camshift.py')
示例#7
0
import cv2 as cv
import numpy as np


def OpenCVCode(imgRGB, depth_colormap):
    images = np.vstack((imgRGB, depth_colormap))
    cv.imshow("RGB and Depth Images", images)


from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_RGBDepth.py')
示例#8
0
        pygame.display.set_caption("OpenCVB - Python_SurfaceBlit.py")
        display = imgRGB.shape[1], imgRGB.shape[0]
        screen = pygame.display.set_mode(display)
        surface = pygame.Surface(display)
    try:
        # uncomment these lines to see the problem with running blit in a callback.
        #if event.type == pygame.QUIT:
        #    pygame.quit()
        #    quit()
        #surface = pygame.image.frombuffer(imgRGB, (imgRGB.shape[1], imgRGB.shape[0]), "RGB")
        #screen.blit(surface, (0, 0))
        #pygame.display.flip()
        pygame.time.wait(1)

    except Exception as exception:
        print(exception)
        cv.waitKey(10000)


# some initialization code
surface = None
print(
    'This script is not working because the surface blit call does not work in a callback.'
)
print(
    'The Python_SurfaceBlitOld.py script works because the blit is inline - not in a callback.'
)
print('To see the problem uncomment the lines above to see the hang...')
from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_SurfaceBlit.py')
title_window = 'Linear Blend'
saveAlpha = 0


## [on_trackbar]
def on_trackbar(val):
    global saveAlpha  # force the callback to reference the global variable.
    saveAlpha = val


## [on_trackbar]

cv.namedWindow(title_window)
## [create_trackbar]
trackbar_name = 'Alpha'
cv.createTrackbar(trackbar_name, title_window, 0, alpha_slider_max,
                  on_trackbar)
on_trackbar(saveAlpha)
## [create_trackbar]


def OpenCVCode(imgRGB, depth_colormap):
    alpha = saveAlpha / alpha_slider_max
    beta = (1.0 - alpha)
    dst = cv.addWeighted(imgRGB, alpha, depth_colormap, beta, 0.0)
    cv.imshow(title_window, dst)


from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_AddWeighted_Trackbar.py')
示例#10
0
    if flow is not None and use_temporal_propagation:
        #warp previous flow to get an initial approximation for the current flow:
        flow = inst.calc(prevgray, gray, warp_flow(flow, flow))
    else:
        flow = inst.calc(prevgray, gray, None)
    prevgray = gray

    cv.imshow('flow', draw_flow(gray, flow))
    if show_hsv:
        cv.imshow('flow HSV', draw_hsv(flow))
    if show_glitch:
        cur_glitch = warp_flow(cur_glitch, flow)
        cv.imshow('glitch', cur_glitch)


if __name__ == '__main__':
    print(__doc__)
    initialized = False
    prevgray = None
    show_hsv = 0
    show_glitch = False
    use_spatial_propagation = False
    use_temporal_propagation = True
    cur_glitch = None
    inst = cv.DISOpticalFlow.create(cv.DISOPTICAL_FLOW_PRESET_MEDIUM)
    inst.setUseSpatialPropagation(use_spatial_propagation)
    flow = None

from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_OpticalFlow.py')
示例#11
0
                   '%d' % digit, (x, y),
                   cv.FONT_HERSHEY_PLAIN,
                   1.0, (200, 0, 0),
                   thickness=1)

    h, w = imgRGB.shape[:2]
    imgRGB = cv.resize(imgRGB, (int(w / 2), int(h / 2)))
    bin = cv.resize(bin, (int(w / 2), int(h / 2)))
    binRGB = np.empty(imgRGB.shape, imgRGB.dtype)
    cv.cvtColor(bin, cv.COLOR_GRAY2BGR, binRGB)
    images = np.empty((h, w * 2, imgRGB.shape[2]), imgRGB.dtype)
    images = cv.hconcat([imgRGB, binRGB])
    cv.imshow('images', images)


if __name__ == '__main__':
    classifier_fn = 'PythonData/digits_svm.dat'
    if not os.path.exists(classifier_fn):
        print('"%s" not found, run digits.py first' % classifier_fn)
        exit

    if True:
        model = cv.ml.SVM_load(classifier_fn)
    else:
        model = cv.ml.SVM_create()
        model.load_(classifier_fn
                    )  #Known bug: https://github.com/opencv/opencv/issues/4969

from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_Digits.py')
示例#12
0
 def Open(self):
     self.p0 = None
     self.use_ransac = True
     print(__doc__)
     PyStreamRun(self.OpenCVCode, titleWindow)
示例#13
0
    gray = cv.equalizeHist(gray)

    t = clock()
    rects = detect(gray, cascade)
    vis = imgRGB.copy()
    draw_rects(vis, rects, (0, 255, 0))
    if not nested.empty():
        for x1, y1, x2, y2 in rects:
            roi = gray[y1:y2, x1:x2]
            vis_roi = vis[y1:y2, x1:x2]
            subrects = detect(roi.copy(), nested)
            draw_rects(vis_roi, subrects, (255, 0, 0))
    dt = clock() - t

    draw_str(vis, (20, 20), 'time: %.1f ms' % (dt * 1000))
    cv.imshow('facedetect', vis)


if __name__ == '__main__':
    print(
        'This example works only occasionally!  Same face model in C# works ok when face is vertical.'
    )
    cascade_fn = "../../opencv/data/haarcascades/haarcascade_frontalface_default.xml"
    nested_fn = "../../opencv/data/haarcascades/haarcascade_eye.xml"

    cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn))
    nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn))

    from PyStream import PyStreamRun
    PyStreamRun(OpenCVCode, 'PyStream_Facedetect.py')
示例#14
0
import cv2 as cv
import numpy as np
import sys

def nothing(*arg):
    pass
def OpenCVCode(imgRGB, depth_colormap):
    gray = cv.cvtColor(imgRGB, cv.COLOR_BGR2GRAY)
    thrs1 = cv.getTrackbarPos('thrs1', 'edge')
    thrs2 = cv.getTrackbarPos('thrs2', 'edge')
    edge = cv.Canny(gray, thrs1, thrs2, apertureSize=5)
    vis = imgRGB.copy()
    vis = np.uint8(vis/2.)
    vis[edge != 0] = (0, 255, 0)
    cv.imshow('edge', vis)

print(__doc__)
cv.namedWindow('edge')
cv.createTrackbar('thrs1', 'edge', 2000, 5000, nothing)
cv.createTrackbar('thrs2', 'edge', 4000, 5000, nothing)
from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_Edge.py')
示例#15
0
 def run(self):
     PyStreamRun(OpenCVCode, titleWindow)
示例#16
0
    hist_scale = val 

def OpenCVCode(imgRGB, depth_colormap):
    global hsv_map, hist_scale, h, s
    small = cv.pyrDown(imgRGB)
    hsv = cv.cvtColor(small, cv.COLOR_BGR2HSV)
    dark = hsv[...,2] < 32
    hsv[dark] = 0
    h = cv.calcHist([hsv], [0, 1], None, [180, 256], [0, 180, 0, 256])
    h = np.clip(h*0.005*hist_scale, 0, 1)
    vis = hsv_map*h[:,:,np.newaxis] / 255.0
    img = cv.resize(imgRGB, (int(vis.shape[1] * imgRGB.shape[1] / imgRGB.shape[0]), vis.shape[1]))
    cv.imshow('img', img)
    cv.imshow('hist', vis)

hsv_map = np.zeros((180, 256, 3), np.uint8)
h, s = np.indices(hsv_map.shape[:2])
hsv_map[:,:,0] = h
hsv_map[:,:,1] = s
hsv_map[:,:,2] = 255
hsv_map = cv.cvtColor(hsv_map, cv.COLOR_HSV2BGR)
#cv.imshow('hsv_map', hsv_map)

cv.namedWindow('hist', 0)
hist_scale = 10

cv.createTrackbar('scale', 'hist', hist_scale, 32, set_scale)

from PyStream import PyStreamRun
PyStreamRun(OpenCVCode, 'PyStream_color_histogram.py')
示例#17
0
def OpenCVCode(imgRGB, depth32f, frameCount):
    global cascade, nested
    gray = cv.cvtColor(imgRGB, cv.COLOR_BGR2GRAY)
    gray = cv.equalizeHist(gray)

    t = clock()
    rects = detect(gray, cascade)
    vis = imgRGB.copy()
    draw_rects(vis, rects, (0, 255, 0))
    if not nested.empty():
        for x1, y1, x2, y2 in rects:
            roi = gray[y1:y2, x1:x2]
            vis_roi = vis[y1:y2, x1:x2]
            subrects = detect(roi.copy(), nested)
            draw_rects(vis_roi, subrects, (255, 0, 0))
    dt = clock() - t

    draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000))
    cv.imshow('facedetect', vis)
    return vis, None

if __name__ == '__main__':
    print('This example works only occasionally!  Same face model in C# works ok when face is vertical.')
    cascade_fn = "../opencv/data/haarcascades/haarcascade_frontalface_default.xml"
    nested_fn  = "../opencv/data/haarcascades/haarcascade_eye.xml"

    cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn))
    nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn))

    PyStreamRun(OpenCVCode, titleWindow)
示例#18
0
 def Open(self):
     self.paused = False
     cv.namedWindow(titleWindow)
     self.rect_sel = RectSelector(titleWindow, self.onrect)
     self.trackers = []
     PyStreamRun(self.OpenCVCode, titleWindow)