Exemplo n.º 1
0
def install_lib_classic(obj, libs):
    """Install libraries."""
    if not obj.is_classic:
        raise RuntimeError('Cannot manage classic libs in retail game folder')
    obj.manager_lib_classic.install(libs)
    obj.manager_lib_classic.export()
    Manager().process_libs()
Exemplo n.º 2
0

def test_drop():
    print("Dropping table", table_test)
    database.actions.drop(table_test)

    with ENGINE.connect():
        table = Table(table_test, META, autoload=True, autoload_with=ENGINE)
        if not table.exists(bind=None):
            print('TABLE DROP SUCCESS!')
        else:
            print(
                "Something went wrong. Please rerun in DEBUG mod. DROP FAILED")


manager = Manager()


@manager.command()
def test_all():
    test_creation()
    test_insert()
    test_remap_without_changes()
    os.execl(sys.executable, 'python', '-m', 'tests.database_test',
             'remap_all')


@manager.command()
def remap_all():
    test_remap_with_all_changes()
    os.execl(sys.executable, 'python', '-m', 'tests.database_test',
Exemplo n.º 3
0
def main():
    camera = cv2.VideoCapture(
        path.join(path.dirname(__file__), "samples/traffic.flv"))
    # camera = cv2.VideoCapture(path.join(path.dirname(__file__), "samples/human.avi"))
    # camera = cv2.VideoCapture(0)
    # KNN background subtractor
    bs = cv2.createBackgroundSubtractorKNN()

    # MOG subtractor
    # bs = cv2.bgsegm.createBackgroundSubtractorMOG(history = background_frame)
    # bs.setHistory(history)

    # GMG
    # bs = cv2.bgsegm.createBackgroundSubtractorGMG(initializationFrames = history)

    cv2.namedWindow("视窗")
    human_manager = Manager()
    frames = 0

    while True:
        print(" -------------------- FRAME %d --------------------" % frames)
        grabbed, frame = camera.read()
        if (grabbed is False):
            print("failed to grab frame.")
            break

        fgmask = bs.apply(frame)

        # this is just to let the background subtractor build a bit of history
        if frames < background_frame:
            frames += 1
            continue

        th = cv2.threshold(fgmask.copy(), 127, 255, cv2.THRESH_BINARY)[1]
        th = cv2.erode(th,
                       cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)),
                       iterations=2)
        dilated = cv2.dilate(th,
                             cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                                       (8, 3)),
                             iterations=2)
        image, contours, _ = cv2.findContours(dilated, cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_SIMPLE)

        found_filtered = []
        # 根据面积过滤一次
        for contour in contours:
            area = cv2.contourArea(contour)
            print("面积 %f" % area)
            if area > min_contour_area:
                found_filtered.append(contour)

        # for ridx, o in enumerate(contours):
        #     for qidx, i in enumerate(contours):
        #         # i 在 o 内
        #         if ridx != qidx and is_inside(cv2.boundingRect(o), cv2.boundingRect(i)):
        #             break
        #         else:
        #             found_filtered.append(i)

        detected_objects = []
        for contour in found_filtered:
            draw_person(frame, contour)
            track_window = cv2.boundingRect(contour)
            detected_objects.append(DetectedObject(track_window))

        print("找到 %d 个物体" % len(detected_objects))

        human_manager.process_detect_objs(detected_objects)

        frames += 1

        cv2.putText(frame, "count: %d" % human_manager.get_num(),
                    (int(20), int(20)), font, 1, (255, 255, 0), 1)
        cv2.imshow("surveillance", frame)

        cv2.waitKey(0)  # 暂停

        if cv2.waitKey(110) & 0xff == 27:
            break
    camera.release()
Exemplo n.º 4
0
def install_lib(obj, libs):
    """Install libraries."""
    obj.manager_lib.install(libs)
    obj.manager_lib.export()
    Manager().process_libs()
Exemplo n.º 5
0
def _manage():
    print('Modifying addons to fit each other...')
    Manager().process()
    Manager().process_libs()
    print('Done!')
Exemplo n.º 6
0
    netG = Generator()
    netD = Discriminator()
    netG.to(device)
    netD.to(device)

    # optimizer
    optimizerG = Adam(netG.parameters(), lr=0.0002, betas=(0.5, 0.999))
    optimizerD = Adam(netD.parameters(), lr=0.0002, betas=(0.5, 0.999))
    schedulerG = lr_scheduler.ExponentialLR(optimizerG, gamma=0.9)
    schedulerD = lr_scheduler.ExponentialLR(optimizerD, gamma=0.9)
    
    # criterion
    criterion = torch.nn.BCELoss()

    # manager
    manager = Manager(netG, netD, optimizerG, optimizerD, criterion, device)

    # generate
    generated_save_path = './generated'
    num_generated_image = 5

    # epochs
    epochs = 500

    # load
    start_epoch = 1
    if os.path.exists('./log/lastest_checkpoint.log'):
        lastest_checkpoint = torch.load('./log/lastest_checkpoint.log')
        lastest_saved_epoch = lastest_checkpoint['epoch']
        netG.load_state_dict(torch.load('./log/G-weight-{:0>8}.log'.format(lastest_saved_epoch)))
        netD.load_state_dict(torch.load('./log/D-weight-{:0>8}.log'.format(lastest_saved_epoch)))
Exemplo n.º 7
0
 def test_merge_namespace(self):
     new_manager = Manager()
     new_manager.add_command(Command(name='new_command'))
     manager.merge(new_manager, namespace='new_namespace')
     self.assertIn('new_namespace.new_command', manager.commands)