コード例 #1
0
def main():
    graph, sess = load_graph(FLAGS.pre_trained_model_path)
    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, FLAGS.width)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, FLAGS.height)
    mp = _mp.get_context("spawn")
    v = mp.Value('i', 0)
    lock = mp.Lock()
    process = mp.Process(target=mario, args=(v, lock))
    process.start()
    while True:
        key = cv2.waitKey(10)
        if key == ord("q"):
            break
        _, frame = cap.read()
        frame = cv2.flip(frame, 1)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        boxes, scores, classes = detect_hands(frame, graph, sess)
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        results = predict(boxes, scores, classes, FLAGS.threshold, FLAGS.width, FLAGS.height)

        if len(results) == 1:
            x_min, x_max, y_min, y_max, category = results[0]
            x = int((x_min + x_max) / 2)
            y = int((y_min + y_max) / 2)
            cv2.circle(frame, (x, y), 5, RED, -1)

            if category == "Open" and x <= FLAGS.width / 3:
                action = 7  # Left jump
                text = "Jump left"
            elif category == "Closed" and x <= FLAGS.width / 3:
                action = 6  # Left
                text = "Run left"
            elif category == "Open" and FLAGS.width / 3 < x <= 2 * FLAGS.width / 3:
                action = 5  # Jump
                text = "Jump"
            elif category == "Closed" and FLAGS.width / 3 < x <= 2 * FLAGS.width / 3:
                action = 0  # Do nothing
                text = "Stay"
            elif category == "Open" and x > 2 * FLAGS.width / 3:
                action = 2  # Right jump
                text = "Jump right"
            elif category == "Closed" and x > 2 * FLAGS.width / 3:
                action = 1  # Right
                text = "Run right"
            else:
                action = 0
                text = "Stay"
            with lock:
                v.value = action
            cv2.putText(frame, "{}".format(text), (x_min, y_min - 5),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, GREEN, 2)
        overlay = frame.copy()
        cv2.rectangle(overlay, (0, 0), (int(FLAGS.width / 3), FLAGS.height), ORANGE, -1)
        cv2.rectangle(overlay, (int(2 * FLAGS.width / 3), 0), (FLAGS.width, FLAGS.height), ORANGE, -1)
        cv2.addWeighted(overlay, FLAGS.alpha, frame, 1 - FLAGS.alpha, 0, frame)
        cv2.imshow('Detection', frame)

    cap.release()
    cv2.destroyAllWindows()
コード例 #2
0
def baseSETemplate(uniprot_id):

    prediction = predict(uniprot_id)

    st.markdown("---")

    st.header("**Results**")

    st.markdown("######")

    profile_col1, profile_col2, profile_col3 = st.beta_columns([12, 1, 12])

    with profile_col1:

        # Protein Profile
        protein_id, protein_name, protein_gene_name, protein_org = prediction[
            2]

        st.subheader("**Protein Profile**")

        st.markdown(
            f"**UniProt ID**:    \n{protein_id}   \n**Gene Name**:   \n{protein_gene_name}   \n**Name**:   \n{protein_name}   \n**Organism**:   \n{protein_org}"
        )

        st.markdown("###")

    with profile_col3:

        # Query Homology Profile

        query_id, query_name, query_type = homology_profile(prediction[0])

        st.subheader("**Predicted Protein Homology Classification**")

        st.markdown(
            f"**InterPro ID**:   \n{query_id}   \n**Name**:   \n{query_name}   \n**Type**:   \n{query_type}"
        )

        st.markdown("###")

    query_reference = prediction[1].columns.tolist()
    query_results = result(query_reference)

    # Protein Metadata Attribute Profile
    st.subheader("**Protein Metadata Attributes**")

    st.markdown(
        "Expand/Collapse the following accordions to view metadata relevant to the protein query"
    )

    for i in query_results:

        df_name, df_result = i[0], i[1]

        with st.beta_expander(df_name):
            st.plotly_chart(df_result, use_container_width=True)

    st.markdown("#")

    st.subheader("**Protein Homology Membership**")

    st.markdown(
        "Explore the protein members under the same homology group as the query protein."
    )

    # st.markdown("###")

    st.markdown(f"**InterPro ID**: {query_id}   \n**Name**:   {query_name}")

    protein_members, protein_members_metadata = protein_membership_profile(
        query_id, query_type)

    with st.beta_expander("Members List"):
        st.table(protein_members)

    with st.beta_expander("Members Metadata"):
        st.table(protein_members_metadata)
コード例 #3
0
def main():
    graph, sess = load_graph(FLAGS.pre_trained_model_path)
    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, FLAGS.width)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, FLAGS.height)
    mp = _mp.get_context("spawn")
    v = mp.Value('i', 0)
    lock = mp.Lock()
    process = mp.Process(target=battle_city, args=(v, lock))
    process.start()
    x_center = int(FLAGS.width / 2)
    y_center = int(FLAGS.height / 2)
    radius = int(min(FLAGS.width, FLAGS.height) / 6)
    while True:
        key = cv2.waitKey(10)
        if key == ord("q"):
            break
        _, frame = cap.read()
        frame = cv2.flip(frame, 1)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        boxes, scores, classes = detect_hands(frame, graph, sess)
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        results = predict(boxes, scores, classes, FLAGS.threshold, FLAGS.width, FLAGS.height)
        if len(results) == 1:
            x_min, x_max, y_min, y_max, category = results[0]
            x = int((x_min + x_max) / 2)
            y = int((y_min + y_max) / 2)
            cv2.circle(frame, (x, y), 5, RED, -1)
            if category == "Closed" and np.linalg.norm((x - x_center, y - y_center)) <= radius:
                action = 0 # Stay
                text = "Stay"
            elif category == "Closed" and is_in_triangle((x, y), [(0, 0), (FLAGS.width, 0),
                                                                  (x_center, y_center)]):
                action = 1  # Up
                text = "Up"
            elif category == "Closed" and is_in_triangle((x, y), [(0, FLAGS.height),
                                                                  (FLAGS.width, FLAGS.height), (x_center, y_center)]):
                action = 2  # Down
                text = "Down"
            elif category == "Closed" and is_in_triangle((x, y), [(0, 0),
                                                                  (0, FLAGS.height),
                                                                  (x_center, y_center)]):
                action = 3  # Left
                text = "Left"
            elif category == "Closed" and is_in_triangle((x, y), [(FLAGS.width, 0), (FLAGS.width, FLAGS.height),
                                                                  (x_center, y_center)]):
                action = 4  # Right
                text = "Right"
            elif category == "Open":
                action = 5  # Fire
                text = "Fire"
            else:
                action = 0
                text = "Stay"
            with lock:
                v.value = action
            cv2.putText(frame, "{}".format(text), (x_min, y_min - 5),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, GREEN, 2)

        overlay = frame.copy()
        cv2.drawContours(overlay, [np.array([(0, 0), (FLAGS.width, 0), (x_center, y_center)])], 0,
                         CYAN, -1)
        cv2.drawContours(overlay, [
            np.array([(0, FLAGS.height), (FLAGS.width, FLAGS.height), (x_center, y_center)])], 0,
                         CYAN, -1)
        cv2.drawContours(overlay, [
            np.array([(0, 0), (0, FLAGS.height), (x_center, y_center)])], 0,
                         YELLOW, -1)
        cv2.drawContours(overlay, [np.array([(FLAGS.width, 0), (FLAGS.width, FLAGS.height), (x_center, y_center)])], 0,
                         YELLOW, -1)
        cv2.circle(overlay, (x_center, y_center), radius, BLUE, -1)
        cv2.addWeighted(overlay, FLAGS.alpha, frame, 1 - FLAGS.alpha, 0, frame)

        cv2.imshow('Detection', frame)

    cap.release()
    cv2.destroyAllWindows()
コード例 #4
0
    help="provide /path/to/image, default 'flowers/test/101/image_07949.jpg'",
    type=str,
    default='flowers/test/101/image_07949.jpg')
parser.add_argument(
    "checkpoint",
    help=
    "provide checkpoint to load the model for prediction, e.g. 'checkpoints/checkpoint_resnet18_1epochs.pth'",
    type=str)
parser.add_argument(
    "--top_k",
    help="provide the number of top probabilities to display, default 1",
    type=int,
    default=1)
parser.add_argument(
    "--category_names",
    help=
    "specify the location of json file to map categories to real flower names, e.g. cat_to_name.json",
    type=str,
    default=None)
parser.add_argument("--gpu",
                    help="use gpu for prediction",
                    action="store_true")
args = parser.parse_args()

#with active_session():
predict(image_path=args.input,
        checkpoint=args.checkpoint,
        topk=args.top_k,
        pred_cat_names=args.category_names,
        use_gpu=args.gpu)
コード例 #5
0
def main():
    graph, sess = load_graph(FLAGS.pre_trained_model_path)

    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, FLAGS.width)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, FLAGS.height)

    mp = _mp.get_context("spawn")
    v = mp.Value('i', 0)
    lock = mp.Lock()
    process = mp.Process(target=mimic, args=(v, lock))
    process.start()

    x_center = int(FLAGS.width / 2)
    y_center = int(FLAGS.height / 2)
    radius = int(min(FLAGS.width, FLAGS.height) / 4)

    while True:
        key = cv2.waitKey(10)
        if key == ord("q"):
            break
        _, frame = cap.read()
        frame = cv2.flip(frame, 1)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        boxes, scores, classes = detect_hands(frame, graph, sess)
        results = predict(boxes, scores, classes, FLAGS.threshold, FLAGS.width,
                          FLAGS.height)
        text = "Oof"

        top_left_square_corr = np.array([(0, 0), (FLAGS.width // 3, 0),
                                         (FLAGS.width // 3, FLAGS.height // 2),
                                         (0, FLAGS.height // 2)])
        bottom_left_square_corr = np.array([(0, FLAGS.height),
                                            (0, FLAGS.height // 2),
                                            (FLAGS.width // 3,
                                             FLAGS.height // 2),
                                            (FLAGS.width // 3, FLAGS.height)])
        bottom_right_square_corr = np.array([
            (FLAGS.width, FLAGS.height),
            (FLAGS.width - FLAGS.width // 3, FLAGS.height),
            (FLAGS.width - FLAGS.width // 4, FLAGS.height - FLAGS.height // 3),
            (FLAGS.width, FLAGS.height - FLAGS.height // 3)
        ])
        top_right_square_corr = np.array([(FLAGS.width, 0),
                                          (FLAGS.width - FLAGS.width // 4, 0),
                                          (FLAGS.width - FLAGS.width // 4,
                                           FLAGS.height // 3),
                                          (FLAGS.width, FLAGS.height // 3)])

        if len(results) == 1:
            x_min, x_max, y_min, y_max, category = results[0]
            x = int((x_min + x_max) / 2)
            y = int((y_min + y_max) / 2)
            cv2.circle(frame, (x, y), 10, RED, -1)

            if category == "Open" and np.linalg.norm(
                (x - x_center, y - y_center)) <= radius:
                action = 1
                text = action
            elif category == "Open" and is_in_square(
                (x, y), top_left_square_corr):
                action = 3
                text = action
            elif category == "Open" and is_in_square(
                (x, y), top_right_square_corr):
                action = 2
                text = action
            elif category == "Closed" and is_in_square(
                (x, y), bottom_right_square_corr):
                action = 4
                text = action
            else:
                action = 0
            with lock:
                v.value = action
            cv2.putText(frame, "{}".format(text), (x_min, y_min - 5),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, GREEN, 2)
        overlay = frame.copy()
        height = FLAGS.height // 3
        width = FLAGS.width // 3

        cv2.drawContours(overlay, [top_left_square_corr], 0, CYAN, -1)
        cv2.drawContours(overlay, [bottom_right_square_corr], 0, RED, -1)
        cv2.drawContours(overlay, [bottom_left_square_corr], 0, GREEN, -1)
        cv2.drawContours(overlay, [top_right_square_corr], 0, YELLOW, -1)
        cv2.circle(overlay, (x_center, y_center), radius, BLUE, -1)
        cv2.addWeighted(overlay, FLAGS.alpha, frame, 1 - FLAGS.alpha, 0, frame)
        cv2.imshow('Detection', frame)

    cap.release()
    cv2.destroyAllWindows()
コード例 #6
0
        count_last = 0

        cv2.namedWindow("hand", flags=cv2.WINDOW_NORMAL)
        cv2.createTrackbar("upper", "hand", 0, 255, nothing)
        cv2.createTrackbar("lower", "hand", 0, 255, nothing)

        while (1):
            try:
                #START SEGMENTING SKIN COLOR
                ret, frame = vc.read()
                frame = cv2.flip(frame, 1)

                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                boxes, scores, classes = detect_hands(frame, graph, sess)
                frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
                results = predict(boxes, scores, classes, 0.6, 640, 480)

                if len(results) == 1:
                    H = frame.shape[0]
                    W = frame.shape[1]
                    black = frame.copy()
                    cv2.rectangle(black, (0, 0), (W, H), (0, 0, 0), -1)
                    x_min, x_max, y_min, y_max, _ = results[0]
                    crop = frame[y_min:y_max, x_min:x_max]
                    black[y_min:y_max, x_min:x_max] = crop
                    cv2.rectangle(frame, (x_min, y_min), (x_max, y_max),
                                  (255, 0, 0), 2)

                    # cv2.rectangle(frame,(450,270),(452,272),(0,255,0),0)
                    # if(cv2.waitKey(20) == 32):
                    # bgr = frame[271, 451]