Wednesday, 2 March 2016

Hi all, just a quick idea I've had:
This code will (should) run separate process for camera stuff, It is a quick draft but im confident it should work seamlessly with Kamil's framework.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def init(self):
    # put your self.registerOutput here
    self.registerOutput("facePos", Obj("x", 0, "y", 0))

def run (self):
    # put your init and global variables here
    xPos = 10
    yPos = 10
    my_pipe, process_pipe = Connection()
    cam = OpenCvProcess(process_pipe)
    cam.daemon = True
    cam.start()

    # main loop
    while 1:
        # put your logic here
        # you can use: output, getInputs, message
        try:
            xPos,yPos = my_pipe.recv()
            self.output("facePos", Obj("x", xPos, "y", yPos))
        except EOFError:
            pass


class OpenCvProcess(Process):
    def __init__(self, pipe):
        # stuff
        self.run(pipe)

    def run(self, pipe):
        cam = cv2.VideoCapture(0)

        while True:
            res, image = cam.read
            #detect face pos
            x,y = (55,4)
            pipe.send((x, y))
            time.sleep(0.01)
Michal

No comments:

Post a Comment