Пример #1
0
args = vars(parser.parse_args())

context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://' + args['address'] + ':' + args['port'])
footage_socket.setsockopt_string(zmq.SUBSCRIBE, '')
footage_socket.set_hwm(1)

footage_socket.RCVTIMEO = 1000  # in milliseconds
count = 0
running = True

from rocketvision import Rate

fps = Rate()
fps.start()

from nada import Nada
from yolo import Yolo
from resnet50 import ResNet50

nada = Nada()

#nn = ResNet50()
nn = Yolo(
    img_size=256, conf_thres=0.60
)  # default is 512 which yeilds about 3.8 fps (i7/940MX), 384 --> 5 fps, 256 --> 7 fps
# nn2 = Yolo(img_size=256, conf_thres = 0.60) # default is 512 which yeilds about 3.8 fps (i7/940MX), 384 --> 5 fps, 256 --> 7 fps

# nn = Yolo(cfg='ultrayolo/cfg/yolov3-tiny.cfg', \
#                weights='ultrayolo/weights/yolov3-tiny.pt', \
Пример #2
0
class ImageProcessor:
    def __init__(self, process):
        self._process = process
        self.running = False
        self.stopped = True
        self._count = 0
        self.count = self._count
        self._srcid = 0
        self.srcid = self._srcid
        self._meta = []
        self.meta = self._meta.copy()
        self._img = []
        self.outimg = self._img.copy()
        self._timestamp = 0
        self.timestamp = self._timestamp
        self.event = Event()
        self.fps = Rate()

        self.history = {}

    def start(self, wait=True, timeout=5.0):
        # start the thread to read frames from the video stream
        print("STARTING ImageProcess...")
        t = Thread(target=self.update, args=())
        t.daemon = True
        t.start()
        start = time.time()
        if wait:
            while not self.isRunning() and ((time.time() - start) <= timeout):
                time.sleep(0.1)

        if not self.isRunning():
            print("WARNING: ImageProcess may not have started!!!")

        return self

    def stop(self, wait=True, timeout=5.0):
        self.running = False
        start = time.time()
        while not self.stopped and ((time.time() - start) <= timeout):
            time.sleep(0.1)

        if self.isRunning():
            print("WARNING: ImageProcess may not have stopped!!!")

    def isRunning(self):
        return self.running

    def process(self, source, srcid, count, timestamp):

        next_frame = False
        if not self.event.isSet():

            #print(f"Triggering on CAM {srcid} - FRAME {count}")
            # copy previous meta data and start a new processing cycle
            self.outimg = self._img.copy()
            self.count = copy.copy(self._count)
            self.meta = self._meta.copy()
            self.srcid = copy.copy(self._srcid)
            self.timestamp = copy.copy(self._timestamp)

            # New cycle
            self._timestamp = timestamp
            self._img = source
            self._count = count
            self._srcid = srcid

            next_frame = True

            self.event.set()

        if self.srcid in self.history:
            history = copy.copy(self.history[self.srcid])

            if count == history[0] and timestamp == history[1]:
                # already processed it
                self.meta = []

        if self.meta != []:
            self.history.update({
                self.srcid:
                (self.count, self.timestamp, self.outimg, self.meta)
            })
            self.list_overlay(self.meta, self.srcid, self.count,
                              self.timestamp)

        return next_frame

    def update(self):
        print("ImageProcessor STARTED!")
        self.fps.start()
        self.stopped = False
        self.running = True
        while (self.running):
            if self.event.wait(0.250):
                #print(f"IMAGE PROCESSING frame {self._count}")
                self._meta = self._process.process(source0=self._img,
                                                   overlay=False)
                #print(f"Frame {self._count} Processed")
                self.fps.update()
                self.event.clear()

        self.stopped = True
        print("ImageProcessor STOPPED")

    def overlay(self, meta, source):
        self._process.overlay(meta, source)

    def overlay_reticle(self, meta, img, scale, timestamp):
        self._process.overlay_reticle(meta=meta,
                                      img=img,
                                      scale=scale,
                                      timestamp=timestamp)

    def list_overlay(self, meta, srcid, count, timestamp):
        self._process.list_overlay(meta, srcid, count, timestamp)
Пример #3
0
class ImageProcessor:
    def __init__(self, process):
        self._process = process
        self.running = False
        self.stopped = True
        self._count = 0
        self.count = self._count
        self._meta = []
        self.meta = self._meta.copy()
        self.event = Event()
        self.fps = Rate()

    def start(self, wait=True, timeout=5.0):
        # start the thread to read frames from the video stream
        print("STARTING ImageProcess...")
        t = Thread(target=self.update, args=())
        t.daemon = True
        t.start()
        start = time.time()
        if wait:
            while not self.isRunning() and ((time.time() - start) <= timeout):
                time.sleep(0.1)

        if not self.isRunning():
            print("WARNING: ImageProcess may not have started!!!")

        return self

    def stop(self, wait=True, timeout=5.0):
        self.running = False
        start = time.time()
        while not self.stopped and ((time.time() - start) <= timeout):
            time.sleep(0.1)

        if self.isRunning():
            print("WARNING: ImageProcess may not have stopped!!!")

    def isRunning(self):
        return self.running

    def process(self, source, count):
        if not self.event.isSet():
            #print(f"Triggering on {count}")
            # copy previous meta data and start a new processing cycle
            self.count = self._count
            self.meta = self._meta.copy()
            self.img = source
            self._count = count
            self.event.set()

        return (self.count, self.meta)

    def update(self):
        print("ImageProcessor STARTED!")
        self.fps.start()
        self.stopped = False
        self.running = True
        while (self.running):
            if self.event.wait(0.250):
                #print(f"IMAGE PROCESSING frame {self._count}")
                self._meta = self._process.process(source0=self.img,
                                                   overlay=False)
                #print(f"Frame {self._count} Processed")
                self.fps.update()
                self.event.clear()

        self.stopped = True
        print("ImageProcessor STOPPED")

    def overlay(self, meta, source):
        self._process.overlay(meta, source)