{"id":4604,"date":"2024-08-31T13:36:18","date_gmt":"2024-08-31T05:36:18","guid":{"rendered":"https:\/\/www.aqwu.net\/wp\/?p=4604"},"modified":"2024-08-31T13:44:37","modified_gmt":"2024-08-31T05:44:37","slug":"hivisionidphoto-%e4%b8%80%e7%a7%8d%e5%ae%9e%e7%94%a8%e7%9a%84%e8%af%81%e4%bb%b6%e7%85%a7%e6%99%ba%e8%83%bd%e5%88%b6%e4%bd%9c%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.aqwu.net\/wp\/?p=4604","title":{"rendered":"HivisionIDPhoto \u4e00\u79cd\u5b9e\u7528\u7684\u8bc1\u4ef6\u7167\u667a\u80fd\u5236\u4f5c\u7b97\u6cd5"},"content":{"rendered":"\n<p>HivisionIDPhoto\u65e8\u5728\u5f00\u53d1\u4e00\u79cd\u5b9e\u7528\u7684\u8bc1\u4ef6\u7167\u667a\u80fd\u5236\u4f5c\u7b97\u6cd5\u3002<\/p>\n\n\n\n<p>\u5b83\u5229\u7528\u4e00\u5957\u5b8c\u5584\u7684\u6a21\u578b\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5b9e\u73b0\u5bf9\u591a\u79cd\u7528\u6237\u62cd\u7167\u573a\u666f\u7684\u8bc6\u522b\u3001\u62a0\u56fe\u4e0e\u8bc1\u4ef6\u7167\u751f\u6210\u3002<\/p>\n\n\n\n<p><strong>HivisionIDPhoto\u53ef\u4ee5\u505a\u5230:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u8f7b\u91cf\u7ea7\u62a0\u56fe<\/li>\n\n\n\n<li>\u6839\u636e\u4e0d\u540c\u5c3a\u5bf8\u89c4\u683c\u751f\u6210\u4e0d\u540c\u7684\u6807\u51c6\u8bc1\u4ef6\u7167\u3001\u516d\u5bf8\u6392\u7248\u7167<\/li>\n\n\n\n<li>\u7f8e\u989c\uff08waiting\uff09<\/li>\n\n\n\n<li>\u667a\u80fd\u6362\u6b63\u88c5\uff08waiting\uff09<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"660\" src=\"https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23-1024x660.png\" alt=\"\" class=\"wp-image-4606\" srcset=\"https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23-1024x660.png 1024w, https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23-300x193.png 300w, https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23-768x495.png 768w, https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23-1320x851.png 1320w, https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23-600x387.png 600w, https:\/\/www.aqwu.net\/wp\/wp-content\/uploads\/2024\/08\/\u56fe\u7247-23.png 1529w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5982\u679cHivisionIDPhoto\u5bf9\u4f60\u6709\u5e2e\u52a9\uff0c\u8bf7star\u8fd9\u4e2arepo\u6216\u63a8\u8350\u7ed9\u4f60\u7684\u670b\u53cb\uff0c\u89e3\u51b3\u8bc1\u4ef6\u7167\u5e94\u6025\u5236\u4f5c\u95ee\u9898\uff01<\/p>\n\n\n\n<p>\u4f7f\u7528\u5efa\u8bae\u66f4\u65b0\u5230\u6700\u65b0\u7684 gradio<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:sh decode:true \">conda create -yn HivisionIDPhotos python=3.10\n\nconda activate HivisionIDPhotos\n\npip install -r requirements.txt\npip install -U gradio\n\npython app.py\n\n<\/pre><\/div>\n\n\n\n<p>\u91cc\u9762\u7684\u4ee3\u7801 gradio \u53ef\u80fd\u9700\u8981\u4fee\u6539\uff0c\u4fee\u6539\u540e\u7684 app.py \u4ee3\u7801<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" >import gradio as gr\nimport onnxruntime\nfrom src.face_judgement_align import IDphotos_create\nfrom hivisionai.hycv.vision import add_background\nfrom src.layoutCreate import generate_layout_photo, generate_layout_image\nimport pathlib\nimport numpy as np\n\nsize_list_dict = {\"\u4e00\u5bf8\": (413, 295), \"\u4e8c\u5bf8\": (626, 413),\n                  \"\u6559\u5e08\u8d44\u683c\u8bc1\": (413, 295), \"\u56fd\u5bb6\u516c\u52a1\u5458\u8003\u8bd5\": (413, 295), \"\u521d\u7ea7\u4f1a\u8ba1\u8003\u8bd5\": (413, 295)}\ncolor_list_dict = {\"\u84dd\u8272\": (86, 140, 212), \"\u767d\u8272\": (255, 255, 255), \"\u7ea2\u8272\": (233, 51, 35)}\n\n\n# \u8bbe\u7f6eGradio examples\ndef set_example_image(example: list) -&gt; dict:\n    #return gr.Image.update(value=example[0])\n    return example[0] \n\n\n# \u68c0\u6d4bRGB\u662f\u5426\u8d85\u51fa\u8303\u56f4\uff0c\u5982\u679c\u8d85\u51fa\u5219\u7ea6\u675f\u52300\uff5e255\u4e4b\u95f4\ndef range_check(value, min_value=0, max_value=255):\n    value = int(value)\n    if value &lt;= min_value:\n        value = min_value\n    elif value &gt; max_value:\n        value = max_value\n    return value\n\n\ndef idphoto_inference(input_image,\n                      mode_option,\n                      size_list_option,\n                      color_option,\n                      render_option,\n                      custom_color_R,\n                      custom_color_G,\n                      custom_color_B,\n                      custom_size_height,\n                      custom_size_width,\n                      head_measure_ratio=0.2,\n                      head_height_ratio=0.45,\n                      top_distance_max=0.12,\n                      top_distance_min=0.10):\n\n    idphoto_json = {\n        \"size_mode\": mode_option,\n        \"color_mode\": color_option,\n        \"render_mode\": render_option,\n    }\n\n    # \u5982\u679c\u5c3a\u5bf8\u6a21\u5f0f\u9009\u62e9\u7684\u662f\u5c3a\u5bf8\u5217\u8868\n    if idphoto_json[\"size_mode\"] == \"\u5c3a\u5bf8\u5217\u8868\":\n        idphoto_json[\"size\"] = size_list_dict[size_list_option]\n    # \u5982\u679c\u5c3a\u5bf8\u6a21\u5f0f\u9009\u62e9\u7684\u662f\u81ea\u5b9a\u4e49\u5c3a\u5bf8\n    elif idphoto_json[\"size_mode\"] == \"\u81ea\u5b9a\u4e49\u5c3a\u5bf8\":\n        id_height = int(custom_size_height)\n        id_width = int(custom_size_width)\n        if id_height &lt; id_width or min(id_height, id_width) &lt; 100 or max(id_height, id_width) &gt; 1800:\n            return {\n                img_output_standard: gr.update(value=None),\n                img_output_standard_hd: gr.update(value=None),\n                notification: gr.update(value=\"\u5bbd\u5ea6\u5e94\u4e0d\u5927\u4e8e\u957f\u5ea6\uff1b\u957f\u5bbd\u4e0d\u5e94\u5c0f\u4e8e100\uff0c\u5927\u4e8e1800\", visible=True)}\n        idphoto_json[\"size\"] = (id_height, id_width)\n    else:\n        idphoto_json[\"size\"] = (None, None)\n\n    # \u5982\u679c\u989c\u8272\u6a21\u5f0f\u9009\u62e9\u7684\u662f\u81ea\u5b9a\u4e49\u5e95\u8272\n    if idphoto_json[\"color_mode\"] == \"\u81ea\u5b9a\u4e49\u5e95\u8272\":\n        idphoto_json[\"color_bgr\"] = (range_check(custom_color_R),\n                                     range_check(custom_color_G),\n                                     range_check(custom_color_B))\n    else:\n        idphoto_json[\"color_bgr\"] = color_list_dict[color_option]\n\n    result_image_hd, result_image_standard, typography_arr, typography_rotate, \\\n    _, _, _, _, status = IDphotos_create(input_image,\n                                         mode=idphoto_json[\"size_mode\"],\n                                         size=idphoto_json[\"size\"],\n                                         head_measure_ratio=head_measure_ratio,\n                                         head_height_ratio=head_height_ratio,\n                                         align=False,\n                                         beauty=False,\n                                         fd68=None,\n                                         human_sess=sess,\n                                         IS_DEBUG=False,\n                                         top_distance_max=top_distance_max,\n                                         top_distance_min=top_distance_min)\n\n    # \u5982\u679c\u68c0\u6d4b\u5230\u4eba\u8138\u6570\u91cf\u4e0d\u7b49\u4e8e1\n    if status == 0:\n        result_messgae = {\n            img_output_standard: gr.update(value=None),\n            img_output_standard_hd: gr.update(value=None),\n            notification: gr.update(value=\"\u4eba\u8138\u6570\u91cf\u4e0d\u7b49\u4e8e1\", visible=True)\n        }\n\n    # \u5982\u679c\u68c0\u6d4b\u5230\u4eba\u8138\u6570\u91cf\u7b49\u4e8e1\n    else:\n        if idphoto_json[\"render_mode\"] == \"\u7eaf\u8272\":\n            result_image_standard = np.uint8(\n                add_background(result_image_standard, bgr=idphoto_json[\"color_bgr\"]))\n            result_image_hd = np.uint8(add_background(result_image_hd, bgr=idphoto_json[\"color_bgr\"]))\n        elif idphoto_json[\"render_mode\"] == \"\u4e0a\u4e0b\u6e10\u53d8(\u767d)\":\n            result_image_standard = np.uint8(\n                add_background(result_image_standard, bgr=idphoto_json[\"color_bgr\"], mode=\"updown_gradient\"))\n            result_image_hd = np.uint8(\n                add_background(result_image_hd, bgr=idphoto_json[\"color_bgr\"], mode=\"updown_gradient\"))\n        else:\n            result_image_standard = np.uint8(\n                add_background(result_image_standard, bgr=idphoto_json[\"color_bgr\"], mode=\"center_gradient\"))\n            result_image_hd = np.uint8(\n                add_background(result_image_hd, bgr=idphoto_json[\"color_bgr\"], mode=\"center_gradient\"))\n\n        if idphoto_json[\"size_mode\"] == \"\u53ea\u6362\u5e95\":\n            result_layout_image = gr.update(visible=False)\n        else:\n            typography_arr, typography_rotate = generate_layout_photo(input_height=idphoto_json[\"size\"][0],\n                                                                      input_width=idphoto_json[\"size\"][1])\n\n            result_layout_image = generate_layout_image(result_image_standard, typography_arr,\n                                                        typography_rotate,\n                                                        height=idphoto_json[\"size\"][0],\n                                                        width=idphoto_json[\"size\"][1])\n\n        result_messgae = {\n            img_output_standard: result_image_standard,\n            img_output_standard_hd: result_image_hd,\n            img_output_layout: result_layout_image,\n            notification: gr.update(visible=False)}\n\n    return result_messgae\n\n\nif __name__ == \"__main__\":\n    HY_HUMAN_MATTING_WEIGHTS_PATH = \".\/hivision_modnet.onnx\"\n    sess = onnxruntime.InferenceSession(HY_HUMAN_MATTING_WEIGHTS_PATH)\n    size_mode = [\"\u5c3a\u5bf8\u5217\u8868\", \"\u53ea\u6362\u5e95\", \"\u81ea\u5b9a\u4e49\u5c3a\u5bf8\"]\n    size_list = [\"\u4e00\u5bf8\", \"\u4e8c\u5bf8\", \"\u6559\u5e08\u8d44\u683c\u8bc1\", \"\u56fd\u5bb6\u516c\u52a1\u5458\u8003\u8bd5\", \"\u521d\u7ea7\u4f1a\u8ba1\u8003\u8bd5\"]\n    colors = [\"\u84dd\u8272\", \"\u767d\u8272\", \"\u7ea2\u8272\", \"\u81ea\u5b9a\u4e49\u5e95\u8272\"]\n    render = [\"\u7eaf\u8272\", \"\u4e0a\u4e0b\u6e10\u53d8(\u767d)\", \"\u4e2d\u5fc3\u6e10\u53d8(\u767d)\"]\n\n    title = \"&lt;h1 id='title'&gt;HivisionIDPhotos&lt;\/h1&gt;\"\n    description = \"&lt;h3&gt;\ud83d\ude0e6.20\u66f4\u65b0\uff1a\u65b0\u589e\u5c3a\u5bf8\u9009\u62e9\u5217\u8868&lt;\/h3&gt;\"\n    css = '''\n    h1#title, h3 {\n      text-align: center;\n    }\n    '''\n\n    demo = gr.Blocks(css=css)\n\n    with demo:\n        gr.Markdown(title)\n        gr.Markdown(description)\n        with gr.Row():\n            with gr.Column():\n                #img_input = gr.Image().style(height=350)\n                img_input = gr.Image(height=350)\n                mode_options = gr.Radio(choices=size_mode, label=\"\u8bc1\u4ef6\u7167\u5c3a\u5bf8\u9009\u9879\", value=\"\u5c3a\u5bf8\u5217\u8868\", elem_id=\"size\")\n                # \u9884\u8bbe\u5c3a\u5bf8\u4e0b\u62c9\u83dc\u5355\n                with gr.Row(visible=True) as size_list_row:\n                    size_list_options = gr.Dropdown(choices=size_list, label=\"\u9884\u8bbe\u5c3a\u5bf8\", value=\"\u4e00\u5bf8\", elem_id=\"size_list\")\n\n                with gr.Row(visible=False) as custom_size:\n                    custom_size_height = gr.Number(value=413, label=\"height\", interactive=True)\n                    custom_size_wdith = gr.Number(value=295, label=\"width\", interactive=True)\n\n                color_options = gr.Radio(choices=colors, label=\"\u80cc\u666f\u8272\", value=\"\u84dd\u8272\", elem_id=\"color\")\n                with gr.Row(visible=False) as custom_color:\n                    custom_color_R = gr.Number(value=0, label=\"R\", interactive=True)\n                    custom_color_G = gr.Number(value=0, label=\"G\", interactive=True)\n                    custom_color_B = gr.Number(value=0, label=\"B\", interactive=True)\n\n                render_options = gr.Radio(choices=render, label=\"\u6e32\u67d3\u65b9\u5f0f\", value=\"\u7eaf\u8272\", elem_id=\"render\")\n\n                img_but = gr.Button('\u5f00\u59cb\u5236\u4f5c')\n                # \u6848\u4f8b\u56fe\u7247\n                example_images = gr.Dataset(components=[img_input],\n                                            samples=[[path.as_posix()]\n                                                     for path in sorted(pathlib.Path('images').rglob('*.jpg'))])\n\n            with gr.Column():\n                notification = gr.Text(label=\"\u72b6\u6001\", visible=False)\n                with gr.Row():\n                    #img_output_standard = gr.Image(label=\"\u6807\u51c6\u7167\").style(height=350)\n                    #img_output_standard_hd = gr.Image(label=\"\u9ad8\u6e05\u7167\").style(height=350)\n                    img_output_standard = gr.Image(label=\"\u6807\u51c6\u7167\", height=350)\n                    img_output_standard_hd = gr.Image(label=\"\u9ad8\u6e05\u7167\", height=350)\n                #img_output_layout = gr.Image(label=\"\u516d\u5bf8\u6392\u7248\u7167\").style(height=350)\n                img_output_layout = gr.Image(label=\"\u516d\u5bf8\u6392\u7248\u7167\", height=350)\n\n\n            def change_color(colors):\n                if colors == \"\u81ea\u5b9a\u4e49\u5e95\u8272\":\n                    return {custom_color: gr.update(visible=True)}\n                else:\n                    return {custom_color: gr.update(visible=False)}\n\n            def change_size_mode(size_option_item):\n                if size_option_item == \"\u81ea\u5b9a\u4e49\u5c3a\u5bf8\":\n                    return {custom_size: gr.update(visible=True),\n                            size_list_row: gr.update(visible=False)}\n                elif size_option_item == \"\u53ea\u6362\u5e95\":\n                    return {custom_size: gr.update(visible=False),\n                            size_list_row: gr.update(visible=False)}\n                else:\n                    return {custom_size: gr.update(visible=False),\n                            size_list_row: gr.update(visible=True)}\n\n        color_options.input(change_color, inputs=[color_options], outputs=[custom_color])\n        mode_options.input(change_size_mode, inputs=[mode_options], outputs=[custom_size, size_list_row])\n\n        img_but.click(idphoto_inference,\n                      inputs=[img_input, mode_options, size_list_options, color_options, render_options,\n                              custom_color_R, custom_color_G, custom_color_B,\n                              custom_size_height, custom_size_wdith],\n                      outputs=[img_output_standard, img_output_standard_hd, img_output_layout, notification],\n                      queue=True)\n        example_images.click(fn=set_example_image, inputs=[example_images], outputs=[img_input])\n\n    #demo.launch(enable_queue=True)\n    demo.launch()\n<\/pre><\/div>\n\n\n\n<p>\u53c2\u7167\u94fe\u63a5\uff1a<a href=\"https:\/\/github.com\/Zeyi-Lin\/HivisionIDPhotos?tab=readme-ov-file\">Zeyi-Lin\/HivisionIDPhotos: \u26a1\ufe0fHivisionIDPhotos: a lightweight and efficient AI ID photos tools. \u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684AI\u8bc1\u4ef6\u7167\u5236\u4f5c\u7b97\u6cd5\u3002 (github.com)<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HivisionIDPhoto\u65e8\u5728\u5f00\u53d1\u4e00\u79cd\u5b9e\u7528\u7684\u8bc1\u4ef6\u7167\u667a\u80fd\u5236\u4f5c\u7b97\u6cd5\u3002 \u5b83\u5229\u7528\u4e00\u5957\u5b8c\u5584\u7684\u6a21\u578b\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5b9e\u73b0\u5bf9\u591a\u79cd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43],"tags":[542],"class_list":["post-4604","post","type-post","status-publish","format-standard","hentry","category-infoarticle","tag-542"],"views":2139,"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4604"}],"version-history":[{"count":5,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4604\/revisions"}],"predecessor-version":[{"id":4611,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4604\/revisions\/4611"}],"wp:attachment":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}