示例#1
0
 def make_graph(self):
     video_detections = load_pickle(
         os.path.join(mydir, "data", "duke_test_seq_cam2_10.pck"))
     ground_truth = load_pickle(
         os.path.join(mydir, "data", "duke_test_seq_cam2_10_gt.pck"))
     video_detections = [
         (frame_idx, imread(os.path.join(mydir, frame)), detections)
         for frame_idx, frame, detections in video_detections
     ]
     return make_graph(video_detections, 60), ground_truth
示例#2
0
 def annotate(self):
     for img_path in self.next():
         img = imread(img_path)
         color = (0, 255, 0) if self.left_to_annotate == 0 else (255, 0, 0)
         img = cv2.putText(
             img,
             "%d: %s" % (self.current_idx, self.db.get(img_path, "-")),
             (50, 100),
             cv2.FONT_HERSHEY_SIMPLEX,
             4,
             color,
             10,
         )
         self.view(img, pause=True)
         print("Not annotated images: %d/%d" %
               (self.left_to_annotate, len(self)))
示例#3
0
    def next(self):
        headers = {}
        while True:
            l = self._fd.readline()
            if not l:
                raise StopIteration
            if not l.strip() and headers:
                break
            if b':' in l:
                i = l.index(b':')
                headers[l[:i]] = l[i + 1:].strip()

        data = self._fd.read(int(headers[b'Content-Length']))
        img = imread(StringIO(data)).view(Frame)
        img.index = self.fcnt
        self.fcnt += 1
        img.timestamp = img.systime = -1  # FIXME
        return img
示例#4
0
文件: netcam.py 项目: hakanardo/vi3o
    def next(self):
        headers = {}
        while True:
            l = self._fd.readline()
            if not l:
                raise StopIteration
            if not l.strip() and headers:
                break
            if ':' in l:
                i = l.index(':')
                headers[l[:i]] = l[i+1:].strip()

        data = self._fd.read(int(headers['Content-Length']))
        img = imread(StringIO(data)).view(Frame)
        img.index = self.fcnt
        self.fcnt += 1
        img.timestamp = img.systime = -1 # FIXME
        return img
示例#5
0
def train(dataset, input_shape):
    net = Net(input_shape)
    optimizer = torch.optim.SGD(net.parameters(), lr=0.01)
    loss = nn.CrossEntropyLoss()
    net.train()
    for i, (path, label) in enumerate(dataset.items_forever()):
        # Read the input data and transform the label to index
        img = imread(path)
        img = cv2.resize(img, input_shape, interpolation=cv2.INTER_NEAREST)
        data = torch.Tensor(img[:, :, 0].flatten())
        target = torch.Tensor([0 if label == "open" else 1]).type(torch.long)

        # Calculate gradients
        optimizer.zero_grad()
        output = net(data)
        batch_loss = loss(output.view(1, -1), target)
        batch_loss.backward()  # Compute sum of gradients
        optimizer.step()

        print(
            f"Iteration {i}: Output {output} vs expected {target} - loss: {batch_loss}"
        )
示例#6
0
 def frame(self, scene, frame):
     return imread(self._path(scene, "img1/%.6d.jpg" % frame))
示例#7
0
        self.on_mouse_motion(x, y)
        self.clicking = False

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        DebugViewer.scroll[0] += dx
        DebugViewer.scroll[1] += dy
        self.clicking = False

    def on_mouse_press(self, x, y, button, modifiers):
        self.clicking = True

    def on_mouse_release(self, x, y, button, modifiers):
        if self.clicking:
            print(DebugViewer.mouse_x, DebugViewer.mouse_y)

if __name__ == '__main__':
    from vi3o import Video, view
    import sys

    if len(sys.argv) < 2:
        print("Usage: python -mvi3o.debugview <video file>")
        exit(-1)

    for fn in sys.argv[1:]:
        if fn.split('.')[-1].lower() in ('mkv', 'mjpg', 'avi', 'mov', 'mp4'):
            for img in Video(sys.argv[1]):
                view(img)
        else:
            from vi3o.image import imread, imshow
            imshow(imread(fn))
示例#8
0
        self.on_mouse_motion(x, y)
        self.clicking = False

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        DebugViewer.scroll[0] += dx
        DebugViewer.scroll[1] += dy
        self.clicking = False

    def on_mouse_press(self, x, y, button, modifiers):
        self.clicking = True

    def on_mouse_release(self, x, y, button, modifiers):
        if self.clicking:
            print(DebugViewer.mouse_x, DebugViewer.mouse_y)

if __name__ == '__main__':
    from vi3o import Video, view
    import sys

    if len(sys.argv) < 2:
        print("Usage: python -mvi3o.debugview <video file>")
        exit(-1)

    for fn in sys.argv[1:]:
        if fn.split('.')[-1] in ('mkv', 'mjpg'):
            for img in Video(sys.argv[1]):
                view(img)
        else:
            from vi3o.image import imread, imshow
            imshow(imread(fn))
示例#9
0
 def frame(self, scene, frame):
     fn = os.path.join(self._path(scene, 'sequences'), '%.7d.jpg' % frame)
     return imread(fn)