Example #1
0
def fill_tab(tab):
    if tab == 'canvas-tab':
        return [
            dash_canvas.DashCanvas(
                id='canvas-stitch',
                width=canvas_width,
                height=canvas_height,
                scale=scale,
                lineWidth=2,
                lineColor='red',
                tool="line",
                hide_buttons=['pencil'],
                image_content=array_to_data_url(
                    np.zeros((height, width), dtype=np.uint8)),
                goButtonTitle='Estimate translation',
            ),
            html.Button('Upload demo data', id='demo'),
            image_upload_zone('upload-stitch', multiple=True, width=45),
        ]
    elif tab == 'result-tab':
        return [
            html.Img(id='stitching-result',
                     src=array_to_data_url(
                         np.zeros((height, width), dtype=np.uint8)),
                     width=canvas_width)
        ]
    else:
        return [
            html.Img(id='bla', src='assets/stitching.gif', width=canvas_width),
        ]
Example #2
0
def fill_tab(tab):
    if tab == "canvas-tab":
        return [
            dash_canvas.DashCanvas(
                id="canvas-stitch",
                width=canvas_width,
                height=canvas_height,
                scale=scale,
                lineWidth=2,
                lineColor="red",
                tool="line",
                hide_buttons=["pencil"],
                image_content=array_to_data_url(
                    np.zeros((height, width), dtype=np.uint8)),
                goButtonTitle="Estimate translation",
            ),
            html.Div(
                children=[
                    html.Div(
                        image_upload_zone("upload-stitch",
                                          multiple=True,
                                          width="100px"))
                ],
                className="upload_zone",
                id="upload",
            ),
        ]
    elif tab == "result-tab":
        return [
            dcc.Loading(
                id="loading-1",
                children=[
                    html.Img(
                        id="stitching-result",
                        src=array_to_data_url(
                            np.zeros((height, width), dtype=np.uint8)),
                        width=canvas_width,
                    )
                ],
                type="circle",
            ),
            html.Div(
                [
                    html.Label("Contrast"),
                    dcc.Slider(id="contrast-stitch",
                               min=0,
                               max=1,
                               step=0.02,
                               value=0.5),
                ],
                className="result_slider",
            ),
            html.Div(
                [
                    html.Label("Brightness"),
                    dcc.Slider(id="brightness-stitch",
                               min=0,
                               max=1,
                               step=0.02,
                               value=0.5),
                ],
                className="result_slider",
            ),
        ]
    return [
        html.Img(id="bla",
                 src=app.get_asset_url("stitch_demo.gif"),
                 width=canvas_width)
    ]
Example #3
0
def automatic_solve_sudoku(server):

    external_stylesheets = [dbc.themes.CYBORG]
    app = dash.Dash(server=server,
                    external_stylesheets=external_stylesheets,
                    routes_pathname_prefix='/project_sudoku_solver/solver/')
    app.title = 'Sovle Sudoku'
    app.config.suppress_callback_exceptions = True

    filename = "all_projects/opencv/project_sudoku_solver/assets/sudoku.jpg"
    img_app3 = io.imread(filename)

    height, width, _ = img_app3.shape
    canvas_width = 500
    canvas_height = round(height * canvas_width / width)
    scale = canvas_width / width

    app.layout = dbc.Jumbotron([
        dbc.Row([
            dbc.Col(html.H1(children='Calcualte Sudoku',
                            style={
                                'textAlign': 'center',
                                'color': '#7FDBFF'
                            }),
                    md=12)
        ],
                align="center",
                style={'backgroundColor': '#111111'}),
        dbc.Row([
            dbc.Col(html.Div(
                children='Upload Sudoku Image and get Instant result',
                style={
                    'textAlign': 'center',
                    'color': '#7FDBFF'
                }),
                    md=12)
        ],
                align="center",
                style={'backgroundColor': '#111111'}),
        html.Hr(),
        dbc.Row([dbc.Col(image_upload_zone('upload-image-bg'), md=12)],
                align="center",
                style={'backgroundColor': '#111111'}),
        html.Hr(),
        dbc.Row([
            dbc.Col(dash_canvas.DashCanvas(
                id='canvas-bg',
                width=canvas_width,
                height=canvas_height,
                scale=scale,
                image_content=array_to_data_url(img_app3),
                lineWidth=4,
                goButtonTitle='Calculate',
                hide_buttons=['line', 'zoom', 'pan'],
            ),
                    width="auto"),
            dbc.Col(
                dcc.Loading(id="loading-1",
                            type="default",
                            children=[
                                html.Img(id='segmentation-bg',
                                         src="assets/new.gif",
                                         width=500),
                            ])),
        ],
                justify="around",
                style={'backgroundColor': '#111111'}),
        html.Hr(),
        dbc.Row([
            dbc.Col(html.H6(children=['Digit Box width'],
                            style={'color': "#e3c439"}),
                    width=2),
            dbc.Col(
                dcc.RangeSlider(
                    id='bg-width-slider',
                    marks={i: '{}'.format(i)
                           for i in range(5, 46)},
                    min=5,
                    max=45,
                    step=1,
                    value=[9, 30]))
        ],
                style={'backgroundColor': '#111111'}),
        dbc.Row([
            dbc.Col(html.H6(children=['Digit Box height'],
                            style={'color': "#e3c439"}),
                    width=2),
            dbc.Col(
                dcc.RangeSlider(
                    id='bg-height-slider',
                    marks={i: '{}'.format(i)
                           for i in range(5, 46)},
                    min=5,
                    max=45,
                    step=1,
                    value=[20, 40]))
        ],
                style={'backgroundColor': '#111111'}),
        dbc.Row([
            dbc.Col(html.H6(children=['Bird Eye View'],
                            style={'color': "#e3c439"}),
                    width=2),
            dbc.Col(
                dcc.RadioItems(id='radio-birdeye',
                               options=[
                                   {
                                       'label': 'No',
                                       'value': False
                                   },
                                   {
                                       'label': 'Yes',
                                       'value': True
                                   },
                               ],
                               value=False,
                               style={'color': '#18a4db'}))
        ],
                style={'backgroundColor': '#111111'}),
        dbc.Row([
            dbc.Col(html.H6(children=['Check ??'], style={'color': "#e3c439"}),
                    width=2),
            dbc.Col(
                dcc.RadioItems(id='radio-calculate',
                               options=[
                                   {
                                       'label': 'Find Number',
                                       'value': False
                                   },
                                   {
                                       'label': 'Solve Sudoku',
                                       'value': True
                                   },
                               ],
                               value=False,
                               style={'color': '#18a4db'}))
        ],
                style={'backgroundColor': '#111111'}),
        html.Hr(),
        dbc.Row(
            html.Img(
                src=
                'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png',
                width='30px'), )
    ])

    # ----------------------- Callbacks -----------------------------

    @app.callback(Output('bg-title', 'children'),
                  [Input('canvas-bg', 'json_data')])
    def modify_bg_title(json_data):
        if json_data:
            return "First Check all digits are in green box  and then solve Sudoku"
        else:
            raise PreventUpdate

    @app.callback(Output('segmentation-bg', 'src'),
                  [Input('canvas-bg', 'json_data')], [
                      State('canvas-bg', 'image_content'),
                      State('bg-height-slider', 'value'),
                      State('bg-width-slider', 'value'),
                      State('radio-birdeye', 'value'),
                      State('radio-calculate', 'value'),
                  ])
    def update_figure_upload(string, image, height, width, birdeye,
                             calculation):

        if string:
            if image is None:
                im = img_app3
            else:
                im = image_string_to_PILImage(image)
                im = np.asarray(im)

            dat, locsgrid, locs, gray, output_image = solve_sudoku(
                im,
                beyeview=birdeye,
                digit_h=(height[0], height[1]),
                digit_w=(width[0], width[1]))
            if calculation:
                dat = compute(locsgrid, locs, gray, output_image)
            return array_to_data_url(dat)
        else:
            raise PreventUpdate

    @app.callback(Output('canvas-bg', 'json_data'),
                  [Input('canvas-bg', 'image_content')])
    def clear_data(image_string):
        return ''

    @app.callback(Output('canvas-bg', 'image_content'),
                  [Input('upload-image-bg', 'contents')])
    def update_canvas_upload(image_string):
        if image_string is None:
            raise ValueError
        if image_string is not None:
            return image_string
        else:
            return None

    @app.callback(Output('canvas-bg', 'lineWidth'),
                  [Input('bg-width-slider', 'value')])
    def update_canvas_linewidth(value):
        return value

    return app.server
Example #4
0
     html.H2(children='Remove image background'),
     dcc.Markdown('''
      Draw on the object of interest, and press remove background.'''),
     dash_canvas.DashCanvas(
         id='canvas-bg',
         width=canvas_width,
         height=canvas_height,
         scale=scale,
         image_content=array_to_data_url(img_app3),
         lineWidth=4,
         goButtonTitle='Remove background',
         hide_buttons=['line', 'zoom', 'pan'],
     ),
     html.H6(children=['Brush width']),
     dcc.Slider(id='bg-width-slider', min=2, max=40, step=1, value=[5]),
     image_upload_zone('upload-image-bg'),
 ],
          className="seven columns"),
 html.Div([
     html.Img(
         src=
         'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png',
         width='30px'),
     html.A(id='gh-link',
            children=['View on GitHub'],
            href="http://github.com/plotly/canvas-portal/"
            "blob/master/apps/remove-background/app.py",
            style={
                'color': 'black',
                'border': 'solid 1px black',
                'float': 'left'
                          children=[
                              dash_canvas.DashCanvas(
                                  id='canvas-stitch',
                                  width=canvas_width,
                                  height=canvas_height,
                                  scale=scale,
                                  lineWidth=2,
                                  lineColor='red',
                                  tool="line",
                                  image_content=array_to_data_url(
                                      np.zeros(
                                          (width, width), dtype=np.uint8)),
                                  goButtonTitle='Estimate translation',
                              ),
                              html.Button('Upload demo data', id='demo'),
                              image_upload_zone(
                                  'upload-stitch', multiple=True, width=45),
                              html.Div(id='sh_x', hidden=True),
                          ]),
                  dcc.Tab(label='Stitched Image',
                          value='result-tab',
                          children=[
                              html.Img(id='stitching-result',
                                       src=array_to_data_url(
                                           np.zeros((height, width),
                                                    dtype=np.uint8)),
                                       width=canvas_width)
                          ])
              ])
 ],
          className="eight columns"),
 html.Div([
Example #6
0
def automatic_solve_sudoku(server):

    external_stylesheets = [dbc.themes.CYBORG]
    app = dash.Dash(server=server,
                    external_stylesheets=external_stylesheets,
                    routes_pathname_prefix='/project_sudoku_solver/solver/')
    app.title = 'Sovle Sudoku'
    app.config.suppress_callback_exceptions = True

    filename = "all_projects/opencv/project_sudoku_solver/assets/sudoku.jpg"
    img_app3 = io.imread(filename)

    height, width, _ = img_app3.shape
    canvas_width = 500
    canvas_height = round(height * canvas_width / width)
    scale = canvas_width / width

    app.layout = dbc.Jumbotron([
        html.Div(
            [
                html.Div([
                    html.H1(children='Calcualte Sudoku'),
                    dcc.Markdown('''
                 Draw on the object of interest, and press calculate'''),
                    image_upload_zone('upload-image-bg'),
                    html.Hr(),
                    dash_canvas.DashCanvas(
                        id='canvas-bg',
                        width=canvas_width,
                        height=canvas_height,
                        scale=scale,
                        image_content=array_to_data_url(img_app3),
                        lineWidth=4,
                        goButtonTitle='Calculate',
                        hide_buttons=['line', 'zoom', 'pan'],
                    ),
                    html.H6(children=['Digit Box width']),
                    dcc.RangeSlider(
                        id='bg-width-slider',
                        marks={i: '{}'.format(i)
                               for i in range(5, 46)},
                        min=5,
                        max=45,
                        step=1,
                        value=[9, 30]),
                    html.H6(children=['Digit Box height']),
                    dcc.RangeSlider(
                        id='bg-height-slider',
                        marks={i: '{}'.format(i)
                               for i in range(5, 46)},
                        min=5,
                        max=45,
                        step=1,
                        value=[20, 40]),
                    html.H6(children=['Bird Eye View']),
                    dcc.RadioItems(id='radio-birdeye',
                                   options=[
                                       {
                                           'label': 'No',
                                           'value': False
                                       },
                                       {
                                           'label': 'Yes',
                                           'value': True
                                       },
                                   ],
                                   value=False),
                    html.H6(children=['Check ??']),
                    dcc.RadioItems(id='radio-calculate',
                                   options=[
                                       {
                                           'label': 'Find Number',
                                           'value': False
                                       },
                                       {
                                           'label': 'Solve Sudoku',
                                           'value': True
                                       },
                                   ],
                                   value=False),
                ],
                         className="seven columns"),
                html.Div(
                    [
                        html.Hr(),
                        html.Img(
                            src=
                            'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png',
                            width='30px'),
                        #             html.A(
                        #                 id='gh-link',
                        #                 children=[
                        #                     'View on GitHub'],
                        #                 href="http://github.com/plotly/canvas-portal/"
                        #                 "blob/master/apps/remove-background/app.py",
                        #                 style={'color': 'black',
                        #                        'border': 'solid 1px black',
                        #                        'float': 'left'}
                        #             ),
                        html.Hr(),
                        html.H3(
                            children='How to use this app and Solve Sudoku',
                            id='bg-title'),
                        html.Img(
                            id='segmentation-bg',
                            src=
                            'all_projects/opencv/project_sudoku_solver/assets/new.gif',
                            width='40%')
                    ],
                    className="four columns")
            ],
            className="row")
    ])

    # ----------------------- Callbacks -----------------------------

    @app.callback(Output('bg-title', 'children'),
                  [Input('canvas-bg', 'json_data')])
    def modify_bg_title(json_data):
        if json_data:
            return "First Check all digit are in green box  and then solve Sudoku"
        else:
            raise PreventUpdate

    @app.callback(Output('segmentation-bg', 'src'),
                  [Input('canvas-bg', 'json_data')], [
                      State('canvas-bg', 'image_content'),
                      State('bg-height-slider', 'value'),
                      State('bg-width-slider', 'value'),
                      State('radio-birdeye', 'value'),
                      State('radio-calculate', 'value'),
                  ])
    def update_figure_upload(string, image, height, width, birdeye,
                             calculation):

        if string:
            if image is None:
                im = img_app3
            else:
                im = image_string_to_PILImage(image)
                im = np.asarray(im)

            dat, locsgrid, locs, gray, output_image = solve_sudoku(
                im,
                beyeview=birdeye,
                digit_h=(height[0], height[1]),
                digit_w=(width[0], width[1]))
            if calculation:
                dat = compute(locsgrid, locs, gray, output_image)
            return array_to_data_url(dat)
        else:
            raise PreventUpdate

    @app.callback(Output('canvas-bg', 'json_data'),
                  [Input('canvas-bg', 'image_content')])
    def clear_data(image_string):
        return ''

    @app.callback(Output('canvas-bg', 'image_content'),
                  [Input('upload-image-bg', 'contents')])
    def update_canvas_upload(image_string):
        if image_string is None:
            raise ValueError
        if image_string is not None:
            return image_string
        else:
            return None

    @app.callback(Output('canvas-bg', 'lineWidth'),
                  [Input('bg-width-slider', 'value')])
    def update_canvas_linewidth(value):
        return value

    return app.server
Example #7
0
 [
     html.Div([
         dcc.Tabs(id='segmentation-tabs',
                  value='segmentation-canvas-tab',
                  children=[
                      dcc.Tab(label='Annotation tool',
                              value='segmentation-canvas-tab',
                              children=[
                                  dash_canvas.DashCanvas(
                                      id='canvas',
                                      width=canvas_width,
                                      height=canvas_height,
                                      scale=scale,
                                      filename=filename,
                                      goButtonTitle='Segmentation'),
                                  image_upload_zone('upload-image'),
                              ]),
                      dcc.Tab(label='Segmentation result',
                              value='segmentation-result-tab',
                              children=[
                                  dcc.Graph(id='segmentation',
                                            figure=image_with_contour(
                                                np.ones_like(img),
                                                img > 0,
                                                shape=(height, width)))
                              ]),
                      dcc.Tab(label='How to use this app',
                              value='segmentation-help-tab',
                              children=[
                                  html.Img(id='segmentation-help',
                                           src='assets/segmentation.gif',