run_cv.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:StormCV2017 作者: 2729StormRobotics 项目源码 文件源码
def main():
    logging.basicConfig(level=logging.DEBUG)
    print('Initializing NetworkTables')
    # NetworkTables.setTeam(2729)
    # NetworkTables.setClientMode()
    # NetworkTables.setIPAddress('10.27.29.202')
    NetworkTables.initialize(server='roboRIO-2729-frc.local')

    print('Creating pipeline')
    pipeline = Retrotape()

    print('Creating video capture')
    # stream = cv2
    #cap = cv2.VideoCapture("http://localhost:1181/?action=stream")
    cap = cv2.VideoCapture(0)
    # cap = cv2.VideoCapture(http://storm-rpi1.local:1181/?action=stream)
    print(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    print(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
    cap.set(cv2.CAP_PROP_EXPOSURE, 0)
    cap.set(cv2.CAP_PROP_BRIGHTNESS, 30)


    print('Running pipeline')
    iteration = 0
    total = 0
    curr_time = datetime.now()
    while cap.isOpened():
        have_frame, frame = cap.read()
        if have_frame:
            pipeline.process(frame)
            currArea = extra_processing(pipeline)
            total += currArea
            iteration += 1
            # print(iteration)
            # print(total)
            table = NetworkTables.getTable('Vision')
            # ***EQUATION DISTANCE VS AREA*** 53111e^(-1.702x)
            # ***Inverse*** ln(A/53111)/-1.702 = d
            # ***Inverse Test2 -1.0142ln(.0000578938x)
            if(iteration % 200 == 0):
                table.putNumber('FPS', 200 / (datetime.now() - curr_time).total_seconds())
                curr_time = datetime.now()
                # table = NetworkTables.getTable('Vision')
                table.putNumber('Average Area', total / 200)
                print(total / 200)
                iteration = 0
                total = 0
            scaling = 6.8
            estDistance = distanceEstimate(currArea * scaling)
            table.putNumber('est_distance', estDistance)
    print('Capture closed')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号