Ejemplo n.º 1
0
def predict(video_path):
    polyfit = Polyfit()
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        loader = tf.train.import_meta_graph(
            './model_test/lane-conv--490--299.meta')
        loader.restore(sess, './model_test/lane-conv--490--299')
        y = tf.get_collection('pred_network')[0]
        graph = tf.get_default_graph()
        input_x = graph.get_operation_by_name('x_input').outputs[0]
        keep_prob = graph.get_operation_by_name('prob').outputs[0]
        cap = cv2.VideoCapture(video_path)
        ret, frame = cap.read()
        while ret:
            ret, frame = cap.read()
            # cv2.imshow("img",frame)
            img_arr = cv2.resize(frame, dsize=(107, 60))
            img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGR2GRAY)
            imgarr = np.reshape(img_arr, newshape=[1, 60, 107, 1])
            predict = sess.run(y, feed_dict={
                input_x: imgarr,
                keep_prob: 1.0
            })[0]
            predict = np.uint8(np.where(predict == 0, 0, 255))
            predict = cv2.resize(predict, dsize=(320, 180))
            warped = warp(predict)
            left_fit, right_fit, vars = polyfit.poly_fit_slide(warped)
            print(left_fit)
            result, offset, Radius, k_error = draw(
                cv2.resize(frame, dsize=(320, 180)), warped, left_fit,
                right_fit)
            cv2.imshow('warped', warped)
            cv2.imshow('res', result)
            cv2.waitKey(1)
                            's')  # 交易日停市
                except:
                    print(key, '日期:', date, '今日停市')
            compute_allfund(date)
        else:
            total = 0
            for key in hold_stocks.keys():
                if hold_stocks[key] != 0:
                    tmp = ts.get_hist_data(key, start=date, end=date)
                    tmp = tmp.reset_index(drop=False)
                    try:
                        if (tmp['close'].iloc[0] - buyprice[key]
                            ) / buyprice[key] <= -0.05:  # 0.05止损
                            trading(key, date, hold_stocks[key],
                                    tmp['close'].iloc[0], 's')
                            print('止损!', date, '股票代码:', key)
                        else:
                            total += tmp['close'].iloc[0] * hold_stocks[key]
                    except:
                        print(key, '日期:', date, '今日停市')
            print(date, '持仓资金为:', round(total, 2))
            compute_allfund(date)


if __name__ == '__main__':
    setting(50000, 0.003)
    main_proc()
    # draw_line.draw(date_list, fund_list, '每日资金情况图')
    draw_line.draw(date_list, rate_list, '持有期收益率情况图')
    info_table.to_csv('个股持有情况分析.csv', encoding='gb18030')
Ejemplo n.º 3
0
 #     cv2.waitKey(0)    # Video process
 #     VideoProcee(input_path='./test5.avi',output_path='./lane_detect.avi',timeF=1,fps=30)
 #     train()
 #     prediction()
 # data_read()
 sess = tf.Session()
 polyfit = Polyfit()
 sess.run(tf.global_variables_initializer())
 loader = tf.train.import_meta_graph('./model_test/lane-conv---99.meta')
 loader.restore(sess, './model_test/lane-conv---99')
 y = tf.get_collection('pred_network')[0]
 graph = tf.get_default_graph()
 input_x = graph.get_operation_by_name('x_input').outputs[0]
 keep_prob = graph.get_operation_by_name('prob').outputs[0]
 cap = cv2.VideoCapture('./test5.avi')
 ret, frame = cap.read()
 while ret:
     s = time.time()
     ret, frame = cap.read()
     imgarr = cv2.resize(frame, dsize=(107, 60))
     predict = cnn_lane(sess, imgarr)
     predict = np.uint8(np.where(predict == 0, 0, 255))
     predict = cv2.resize(predict, dsize=(320, 180))
     warped = warp(predict)
     left_fit, right_fit, vars = polyfit.poly_fit_slide(warped)
     result, offset, Radius, k_error = draw(
         cv2.resize(frame, dsize=(320, 180)), warped, left_fit, right_fit)
     print('Total;', time.time() - s)
     cv2.imshow('warped', warped)
     cv2.imshow('res', result)
     cv2.waitKey(1)