Exemplo n.º 1
0
    def __init__(self, modelName, useWebcam, **kwargs):
        self.modelName = modelName
        self.useWebcam = useWebcam
        self.videoIndex = 0
        self.webcamFlip = True
        self.delay = 0.025  #ms
        self.autoStart = True
        self.interpolateResult = True
        self.image_queue = queue.Queue(5)
        self.res_queue = queue.Queue(5)

        for k, v in kwargs.items():
            exec('self.' + k + '=v')

        self.net = hs.HS(modelName, **kwargs)
        if self.autoStart:
            if self.useWebcam:
                self.video_capture = cv2.VideoCapture(self.videoIndex)
                self._video_thread = threading.Thread(target=self._get_image,
                                                      args=())
                self._video_thread.start()
            self.start()
Exemplo n.º 2
0
#! /usr/bin/env python3

# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

# Note: This demo needs 2 HS devices

import numpy as np, cv2, sys
sys.path.append('../../api/')
import hsapi as hs
import pdb
WEBCAM = False  # Set to True if use Webcam

net = hs.HS('FaceRec', zoom=True, verbose=2)
net2 = hs.HS('FaceDetector', deviceIdx=1, zoom=True, verbose=0, threshSSD=0.55)

if WEBCAM: video_capture = cv2.VideoCapture(0)
C = 5

try:
    while True:
        if WEBCAM: _, img = video_capture.read()
        else: img = None

        result = net2.run(img)

        # Record 1st face
        key = cv2.waitKey(5)
        if len(result[1]) > 0:
            box = result[1][0]
            if box[5] - box[3] > 10 or box[4] - box[2] > 10:
Exemplo n.º 3
0
# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

# Import libs
import cv2, sys, numpy as np
sys.path.append('../../api/')
import hsapi as hs

# Load CNN to device and set scale / mean
net = hs.HS('mnist')
imgRoot = '../misc/2018_mnist/%d.jpg'

print('Hello')
for n in [1, 2, 3, 4]:
    imgname = imgRoot % n
    img = cv2.imread(imgname)
    result = net.run(img)
    print(result[1])

net.quit()
Exemplo n.º 4
0
#! /usr/bin/env python3

# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

import numpy as np, cv2, sys

sys.path.append('../../api/')
import hsapi as hs

WEBCAM = False  # Set to True if use Webcam

net = hs.HS('SketchGuess', zoom=True, verbose=2)
if WEBCAM: video_capture = cv2.VideoCapture(0)

# Label paths
fcl2 = open('../misc/class_list.txt', 'r')
fcl = open('../misc/class_list_chn.txt', 'r')
class_list = fcl.readlines()
class_list_eng = fcl2.readlines()
cls = []

# Image processing params
p1 = 120
p2 = 45
ROI_ratio = 0.1

stage = 0

for line in class_list:
    cls.append(line.split(' ')[0])
Exemplo n.º 5
0
#! /usr/bin/env python3

# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

import numpy as np, cv2, sys

sys.path.append('../../api/')
import hsapi as hs

WEBCAM = False  # Set to True if use Webcam

net = hs.HS('GoogleNet', zoom=True, verbose=2)
if WEBCAM: video_capture = cv2.VideoCapture(0)

while True:
    if WEBCAM: _, img = video_capture.read()
    else: img = None

    # Get image descriptor
    result = net.run(img)
    key = cv2.waitKey(5)
    prob = net.record(result, key, saveFilename='../misc/record.dat', numBin=5)

    if prob is not None:
        cv2.putText(result[0], '%d' % (prob.argmax() + 1), (50, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 7)
        cv2.putText(result[0], '%d' % (prob.argmax() + 1), (50, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 255), 3)
    cv2.imshow("Scene Recorder", result[0])
    cv2.waitKey(1)
Exemplo n.º 6
0
#! /usr/bin/env python3

# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

import numpy as np, cv2, sys
sys.path.append('../../api/')
import hsapi as hs

WEBCAM = False  # Set to True if use Webcam
net = hs.HS('ObjectDetector', zoom=True, verbose=2)
if WEBCAM: video_capture = cv2.VideoCapture(0)

try:
    while True:
        if WEBCAM: _, img = video_capture.read()
        else: img = None
        result = net.run(img)
        img = net.plotSSD(result)
        cv2.imshow("20 VOC Object Detector", img)
        cv2.waitKey(1)
finally:
    net.quit()
Exemplo n.º 7
0
# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

# Import libs
import cv2, sys, numpy as np
sys.path.append('../../api/')
import hsapi as hs

# Load CNN to device and set scale / mean
net = hs.HS('mnist', zoom=False, verbose=2)

try:
    while (1):
        image = net.getImage()
        cv2.imshow('image', image)
        cv2.waitKey(1)
finally:
    net.quit()
Exemplo n.º 8
0
#! /usr/bin/env python3

# Copyright(c) 2018 Senscape Corporation.
# License: Apache 2.0

import numpy as np, cv2, sys

sys.path.append('../../api/')
import hsapi as hs

WEBCAM = False  # Set to True if use Webcam
net = hs.HS('FaceDetector', zoom=True, verbose=2, threshSSD=0.55)
if WEBCAM: video_capture = cv2.VideoCapture(0)

while True:
    if WEBCAM: _, img = video_capture.read()
    else: img = None
    result = net.run(img)
    img = net.plotSSD(result)
    cv2.imshow("Face Detector", img)
    cv2.waitKey(1)
Exemplo n.º 9
0
 def __init__(self):
     self.net = hs.HS('FaceDetector', zoom=True, verbose=2, threshSSD=0.55)