예제 #1
0
def get_detector_params() -> Tuple[float, int, int]:
    sb.markdown("Params of detector")
    scale_factor_feat_det = sb.slider('Chose scale factor for feature detector', 1.01, 1.3, 1.01)
    max_num_of_features = sb.slider("Select number of features", 30, 5000, 1000)
    num_of_levels = sb.number_input("Write number of level for feature detector",
                                    min_value=2, max_value=16, value=16)
    return scale_factor_feat_det, max_num_of_features, num_of_levels
예제 #2
0
def get_camera_params() -> Tuple[int, int]:
    sb.markdown("Params of camera")
    frame_width = sb.number_input("Width of input frame",
                                  min_value=120,
                                  max_value=1920,
                                  value=640)
    frame_height = int(3 / 4 * frame_width)
    return frame_width, frame_height
예제 #3
0
def get_marker_params(frame_height: int) -> Tuple[int, str, str]:
    sb.markdown("Params of marker")
    marker_size = sb.number_input("Size of marker",
                                  min_value=6,
                                  max_value=frame_height,
                                  value=64)
    path_to_marker = sb.text_input("Write path to custom marker in .jpg or .png formats",
                                   "./src/data/markers/marker23.png")
    full_path_to_marker = os.path.abspath(path_to_marker)
    path_to_obj = sb.text_input("Write path to custom area form",
                                "./src/data/3dmodels/Cylinder.obj")
    full_path_to_obj = os.path.abspath(path_to_obj)
    return marker_size, full_path_to_marker, full_path_to_obj
예제 #4
0
def get_aruco_marker_params() -> Tuple[str, int, float]:
    sb.markdown("Params of marker")
    marker_size = sb.selectbox("Chose aruco marker size",
                               ("7x7", "6x6", "5x5", "4x4"))
    marker_idx = sb.number_input("Select marker index",
                                 min_value=0,
                                 max_value=250,
                                 value=23)
    dictionary = cv2.aruco.Dictionary_get(ARUCO_MARKER_SIZE[marker_size])
    marker_image = cv2.aruco.drawMarker(dictionary, marker_idx, 75, 1)
    sb.image(marker_image)
    marker_world_size = sb.number_input("Lenght of real world marker",
                                        min_value=0.0,
                                        max_value=100.0,
                                        value=0.05)
    return marker_size, marker_idx, marker_world_size
예제 #5
0
def get_calibration_params() -> Tuple[int, int, str, str]:
    sb.markdown("Params of cameara calibration porcesss")

    path_to_camera_params = sb.text_input("Path to camera params",
                                          "camera_params.json")
    board_height = sb.number_input("Board height", 
                                    min_value=3,
                                    max_value=100,
                                    value=9)
    board_width = sb.number_input("Board width", 
                                   min_value=3,
                                   max_value=100,
                                   value=6)
    path_to_images = sb.text_input("Path to images with board",
                                    "./src/data/calibration")
    return board_height, board_width, path_to_images, path_to_camera_params
예제 #6
0
def get_workzone_params() -> Tuple[int, int, int, int]:
    sb.markdown("Params of robot workzone")
    wz_center_x = sb.number_input("X coordinate of workzone center",
                                  min_value=0,
                                  max_value=500,
                                  value=0)
    wz_center_y = sb.number_input("Y coordinate of workzone center",
                                  min_value=0,
                                  max_value=500,
                                  value=0)
    wz_height = sb.number_input("Height of workzone",
                                min_value=1,
                                max_value=100,
                                value=14)
    wz_width = sb.number_input("Width of workzone",
                               min_value=1,
                               max_value=100,
                               value=14)
    return wz_center_x, wz_center_y, wz_height, wz_width
예제 #7
0
def about_me():
    side.markdown(
        '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">',
        unsafe_allow_html=True)
    side.image(Image.open(
        urlopen(
            "https://avatars2.githubusercontent.com/u/34905288?s=400&u=c52b3b2744adf04a26a742000fa83a5c1ea5f92d&v=4"
        )),
               width=200)

    side.subheader("Akash Dave")
    side.markdown(
        "Hi! I am in superlove with data and I do magic using Python. Relax Guys! I am not saying Java is bad."
    )

    side.markdown(
        '<a href="https://github.com/akashdve"><i class="fa fa-github" style="font-size:36px;"></i></a>'
        '<a href="https://linkedin.com/in/akashdave98"><i class="fa fa-linkedin" style="font-size:36px; padding-left:16px;"></i></a>',
        unsafe_allow_html=True)
예제 #8
0
def main():

    ###########################################################
    st.set_page_config(page_title="Handy Data Explorer App")
    st.markdown(hide_streamlit_style, unsafe_allow_html=True)
    st.title("Handy Data Explorer App ({})".format(Config.VERSION))
    st.markdown("Wanna know what your data mean?")
    side.markdown(
        "<button type='button' class='btn btn-primary'>Note:</button> More features coming soon",
        unsafe_allow_html=True)
    side.markdown("This webapp is developed under DOHackathon.")
    side.markdown("Why so simple?")
    side.markdown(
        "Well, I am not a front-end guy. I always tend to search for a simpler and quicker solution to build UI."
        " I came across this wonderful framework <a href='http://streamlit.io'>Streamlit</a> and thought of trying it out.",
        unsafe_allow_html=True)
    side.header("About Me")
    about_me()
    ###########################################################

    source = st.text_input("Enter the source of the dataset")
    st.markdown(HTML_P_TAG_START + "OR" + HTML_P_TAG_END,
                unsafe_allow_html=True)
    file = st.file_uploader("Upload a file (.csv, .xlsx, .json, .df)")

    if source and file:
        st.warning("Please select either source or upload a file")

    main_df = load_data_from_source(source=file if file else source)
    # numeric_cols = main_df.select_dtypes(include=['int16', 'int32', 'int64', 'float16', 'float32', 'float64']).columns

    st.markdown("<hr>", unsafe_allow_html=True)
    st.header("Data Insights")
    st.markdown("<hr>", unsafe_allow_html=True)
    if not (source and file):
        st.info(
            "using example dataset (Taken from Amazon product reviews dataset)"
        )
    st.dataframe(main_df.head())

    st.markdown("<hr>", unsafe_allow_html=True)
    st.markdown(HTML_BREAK + HTML_P_TAG_START + HTML_BOLD_START +
                "Heatmap (for numeric columns)" + HTML_BOLD_END +
                HTML_P_TAG_END,
                unsafe_allow_html=True)
    fig = sns.heatmap(main_df.corr(), annot=True).get_figure()
    heatmap_temp_path = get_temp_path("heatmap.png")
    fig.savefig(heatmap_temp_path)
    st.image(Image.open(heatmap_temp_path))

    st.markdown("<hr>", unsafe_allow_html=True)
    st.markdown(HTML_BREAK + HTML_P_TAG_START + HTML_BOLD_START +
                "Pair Plots (for numeric columns)" + HTML_BOLD_END +
                HTML_P_TAG_END,
                unsafe_allow_html=True)
    pairplot_temp_path = get_temp_path("pairplot.png")
    sns.pairplot(main_df).savefig(pairplot_temp_path)
    st.image(Image.open(pairplot_temp_path))

    st.markdown("<hr>", unsafe_allow_html=True)

    st.header("Min/Max/Count/Freq")
    show_column_insights(main_df)

    st.markdown("<hr>", unsafe_allow_html=True)

    st.header("Wordcloud of non-numeric columns")
    show_wordcloud(main_df)
예제 #9
0
def main_aruco() -> None:
    st.title("Configure params for worzkone")
    sb.markdown("Params of rendering")
    frame_width, frame_height = get_camera_params()
    marker_size, marker_idx, marker_world_size = get_aruco_marker_params()
    scale_factor_model = get_model_params()
    wz_cx, wz_cy, wz_height, wz_width = get_workzone_params()

    camera_params: Optional[CameraParams] = None
    show_calibration_params = sb.checkbox("Camera calibration", value=False)
    if show_calibration_params:
        board_height, board_width, path_to_images, path_to_camera_params = get_calibration_params(
        )
        if os.path.isfile(path_to_camera_params):
            camera_params = load_camera_params(path_to_camera_params)
        else:
            st.warning("Estimate camera params!")
            st.warning("Press 'Calibrate camera' button")

        if sb.button("Calibrate cemera"):
            st.write("Start camera calibration process")
            with st.spinner("Calibrating camera..."):
                camera_params = calibrate_camera(path_to_images, frame_height,
                                                 frame_width, board_height,
                                                 board_width)
            save_camera_params(camera_params, path_to_camera_params)
            st.success("Camera was calibrated successfully")
            st.write("Camera was calibarted")

    viewer = st.image(np.zeros((frame_height, frame_width, 3)))

    cap = get_cap()
    cap.set(3, frame_height)
    cap.set(4, frame_width)

    params = dict(frame_width=frame_width,
                  frame_height=frame_height,
                  marker_size=marker_size,
                  marker_world_size=marker_world_size,
                  scale_factor_model=scale_factor_model,
                  marker_idx=marker_idx,
                  wz_cx=wz_cx,
                  wz_cy=wz_cy,
                  wz_height=wz_height,
                  wz_width=wz_width,
                  camera_params=camera_params.to_dict()
                  if camera_params is not None else {})

    st.subheader("Zone estimation configuration:")
    st.json(params)

    path_to_config = sb.text_input("Path to config", "aruco_config.json")
    if sb.button('Save config'):
        save_config(path_to_config, params)
        st.write(f'Config saved to {path_to_config}')

    if sb.button('Save and Exit'):
        save_config(path_to_config, params)
        st.write('Exit configure')
        cap.release()
        exit(0)

    zone = Workzone(wz_cx, wz_cy, wz_height, wz_width)
    estimator = ArucoZoneEstimator(marker_world_size,
                                   ARUCO_MARKER_SIZE[marker_size], marker_idx,
                                   camera_params, zone)
    while True:
        ret, scene = cap.read()
        if not ret:
            break

        zone_polygon = estimator.estimate(scene)
        zone_polygon = np.array(zone_polygon).reshape(-1, 1, 2)
        zone_polygon = np.clip(zone_polygon, 0, np.inf)
        scene = cv2.polylines(scene, [np.int32(zone_polygon)], True,
                              (255, 0, 0), 2, cv2.LINE_AA)
        viewer.image(scene, channels='BGR')
    cap.release()
예제 #10
0
def get_model_params() -> float:
    sb.markdown("Params of 3d model")
    return sb.number_input("Write scaled factor for 3d model of workzone",
                           1e-4, 1e4, 10.0)
예제 #11
0
def main_features() -> None:
    st.title("Configure params for worzkone")
    sb.markdown("Params of rendering")
    draw_matches = sb.checkbox("Draw matches", value=False)
    frame_width, frame_height = get_camera_params()
    marker_size, full_path_to_marker, full_path_to_obj = get_marker_params(frame_height)
    scale_factor_feat_det, max_num_of_features, num_of_levels = get_detector_params()
    scale_factor_model = get_model_params()
    board_height, board_width, path_to_images, path_to_camera_params = get_calibration_params()
    
    camera_params: Optional[CameraParams] = None
    if os.path.isfile(path_to_camera_params):
        camera_params = load_camera_params(path_to_camera_params)
    else:
        st.warning("Estimate camera params!")
        st.warning("Press 'Calibrate camera' button")

    if sb.button("Calibrate camera"):
        st.write("Start camera calibration process")
        camera_params = calibrate_camera(path_to_images, 
                                         frame_height,
                                         frame_width,
                                         board_height,
                                         board_width)
        save_camera_params(camera_params, path_to_camera_params)
        # process.join()
        st.write("Camera was calibarted")

    viewer = st.image(np.zeros((frame_height, frame_width, 3)))

    cap = get_cap()
    cap.set(3, frame_height)
    cap.set(4, frame_width)

    params = dict(
        frame_width=frame_width,
        frame_height=frame_height,
        marker_size=marker_size,
        path_to_marker=full_path_to_marker,
        path_to_obj=full_path_to_obj,
        scale_factor_model=scale_factor_model,
        scale_factor_feat_det=scale_factor_feat_det,
        max_num_of_features=max_num_of_features,
        num_of_levels=num_of_levels
    )
    st.json(params)

    if sb.button('Save config'):
        save_config("CustomConfig.json", params)
        st.write('Config saved YOUR_CUSTOM_CONFIG.json')

    if sb.button('Save and Exit'):
        st.write('Exit configure')
        save_config("CustomConfig.json", params)
        cap.release()
        exit(0)

    workzone_model = OBJ("src/data/3dmodels/Cylinder.obj", swapyz=True)
    renderer = RenderZone(workzone_model, scale_factor_model, (7, 7))
    estimator = ArucoZoneEstimator(0.045, ARUCO_MARKER_SIZE['7x7'], camera_params)
    while True:
        ret, scene = cap.read()
        if not ret:
            break
        
        scene = estimator.estimate(scene, None)
        viewer.image(scene, channels='BGR')
    cap.release()