6 Commits

78 changed files with 407 additions and 341 deletions

View File

@ -8,5 +8,12 @@
</list> </list>
</option> </option>
</inspection_tool> </inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N806" />
</list>
</option>
</inspection_tool>
</profile> </profile>
</component> </component>

303
.idea/workspace.xml generated
View File

@ -4,6 +4,22 @@
<list default="true" id="e58b655a-3a9b-4001-b4da-39e07ab46629" name="Default Changelist" comment=""> <list default="true" id="e58b655a-3a9b-4001-b4da-39e07ab46629" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.rst" beforeDir="false" afterPath="$PROJECT_DIR$/README.rst" afterDir="false" /> <change beforePath="$PROJECT_DIR$/README.rst" beforeDir="false" afterPath="$PROJECT_DIR$/README.rst" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/data_dlib/dlib_face_recognition_resnet_model_v1.dat" beforeDir="false" afterPath="$PROJECT_DIR$/data/data_dlib/dlib_face_recognition_resnet_model_v1.dat" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/data_dlib/shape_predictor_5_face_landmarks.dat" beforeDir="false" afterPath="$PROJECT_DIR$/data/data_dlib/shape_predictor_5_face_landmarks.dat" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/data_dlib/shape_predictor_68_face_landmarks.dat" beforeDir="false" afterPath="$PROJECT_DIR$/data/data_dlib/shape_predictor_68_face_landmarks.dat" afterDir="false" />
<change beforePath="$PROJECT_DIR$/face_reco_from_camera.py" beforeDir="false" afterPath="$PROJECT_DIR$/face_reco_from_camera.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/features_extraction_to_csv.py" beforeDir="false" afterPath="$PROJECT_DIR$/features_extraction_to_csv.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/get_faces_from_camera.py" beforeDir="false" afterPath="$PROJECT_DIR$/get_faces_from_camera.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/how_to_use_camera.py" beforeDir="false" afterPath="$PROJECT_DIR$/how_to_use_camera.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/Dlib_Face_recognition_by_coneypo.pptx" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/Dlib_Face_recognition_by_coneypo.pptx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/face_reco_single_person.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/face_reco_single_person.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/face_reco_single_person_customize_name.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/face_reco_single_person_customize_name.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/face_reco_two_people.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/face_reco_two_people.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/face_reco_two_people_in_database.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/face_reco_two_people_in_database.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/get_face_from_camera.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/get_face_from_camera.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/get_face_from_camera_out_of_range.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/get_face_from_camera_out_of_range.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/introduction/overview.png" beforeDir="false" afterPath="$PROJECT_DIR$/introduction/overview.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -11,68 +27,36 @@
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FUSProjectUsageTrigger">
<session id="2127136746">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.4" value="1" />
<entry key="project.open.time.5" value="1" />
<entry key="project.opened" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="png" value="1" />
<entry key="txt" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Image" value="1" />
<entry key="PLAIN_TEXT" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="rst" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="ReST" value="2" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/README.rst">
<provider selected="true" editor-type-id="restructured-text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/get_faces_from_camera.py"> <entry file="file://$PROJECT_DIR$/get_faces_from_camera.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="67"> <state relative-caret-position="309">
<caret line="12" column="34" selection-start-line="12" selection-start-column="34" selection-end-line="12" selection-end-column="34" /> <caret line="69" selection-start-line="69" selection-end-line="69" />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/get_features_into_CSV.py"> <entry file="file://$PROJECT_DIR$/features_extraction_to_csv.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="83"> <state relative-caret-position="248">
<caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="16" /> <caret line="73" column="36" selection-start-line="73" selection-start-column="36" selection-end-line="73" selection-end-column="36" />
<folding>
<element signature="e#491#501#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/face_reco_from_camera.py"> <entry file="file://$PROJECT_DIR$/face_reco_from_camera.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="127"> <state relative-caret-position="489">
<caret line="89" column="22" lean-forward="true" selection-start-line="89" selection-start-column="22" selection-end-line="89" selection-end-column="22" /> <caret line="160" column="23" lean-forward="true" selection-start-line="160" selection-start-column="23" selection-end-line="160" selection-end-column="23" />
<folding> <folding>
<element signature="e#230#264#0" expanded="true" /> <element signature="e#230#264#0" expanded="true" />
</folding> </folding>
@ -80,36 +64,38 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/requirements.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76">
<caret line="4" column="16" lean-forward="true" selection-start-line="4" selection-start-column="16" selection-end-line="4" selection-end-column="16" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/introduction/face_reco_two_people_in_database.png">
<provider selected="true" editor-type-id="images" />
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/README.rst">
<provider selected="true" editor-type-id="restructured-text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/how_to_use_camera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="513">
<caret line="27" column="13" selection-start-line="27" selection-start-column="13" selection-end-line="27" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
</leaf> </leaf>
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>path_photos_from_camera</find>
<find>path_csv_from_photos</find>
<find>facerec</find>
<find>img</find>
<find>feature_mean_list_personX</find>
<find>feature_list_personX</find>
<find>feature</find>
<find>features_list_personX</find>
<find>feature_mean_personX</find>
<find>data_csvs</find>
<find>features_known_arr</find>
<find>with</find>
</findStrings>
<replaceStrings>
<replace>face_rec</replace>
<replace>img_rd</replace>
<replace>descriptor_mean_list_personX</replace>
<replace>features_list_personX</replace>
<replace>features_mean_personX</replace>
</replaceStrings>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
@ -117,15 +103,21 @@
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
<list> <list>
<option value="$PROJECT_DIR$/requirements.txt" /> <option value="$PROJECT_DIR$/requirements.txt" />
<option value="$PROJECT_DIR$/get_features_into_CSV.py" />
<option value="$PROJECT_DIR$/get_origin.py" />
<option value="$PROJECT_DIR$/test.py" />
<option value="$PROJECT_DIR$/features_extraction_to_csv.py" />
<option value="$PROJECT_DIR$/get_faces_from_camera.py" />
<option value="$PROJECT_DIR$/README.rst" /> <option value="$PROJECT_DIR$/README.rst" />
<option value="$PROJECT_DIR$/face_reco_from_camera.py" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds"> <component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="740" /> <option name="x" value="-281" />
<option name="y" value="86" /> <option name="y" value="574" />
<option name="width" value="1194" /> <option name="width" value="1910" />
<option name="height" value="987" /> <option name="height" value="741" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView"> <component name="ProjectView">
@ -145,11 +137,6 @@
<item name="Dlib_face_recognition_from_camera" type="462c0819:PsiDirectoryNode" /> <item name="Dlib_face_recognition_from_camera" type="462c0819:PsiDirectoryNode" />
<item name="data" type="462c0819:PsiDirectoryNode" /> <item name="data" type="462c0819:PsiDirectoryNode" />
</path> </path>
<path>
<item name="Dlib_face_recognition_from_camera" type="b2602c69:ProjectViewProjectNode" />
<item name="Dlib_face_recognition_from_camera" type="462c0819:PsiDirectoryNode" />
<item name="introduction" type="462c0819:PsiDirectoryNode" />
</path>
</expand> </expand>
<select /> <select />
</subPane> </subPane>
@ -157,6 +144,10 @@
<pane id="Scope" /> <pane id="Scope" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="last_opened_file_path" value="/media/con/Ubuntu 18.0/Face_Recognition" />
</component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
<list> <list>
@ -191,6 +182,27 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="features_extraction_to_csv" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Dlib_face_recognition_from_camera" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/features_extraction_to_csv.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="get_faces_from_camera" type="PythonConfigurationType" factoryName="Python" temporary="true"> <configuration name="get_faces_from_camera" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Dlib_face_recognition_from_camera" /> <module name="Dlib_face_recognition_from_camera" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -212,7 +224,7 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="get_features_into_CSV" type="PythonConfigurationType" factoryName="Python" temporary="true"> <configuration name="get_origin" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Dlib_face_recognition_from_camera" /> <module name="Dlib_face_recognition_from_camera" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
@ -224,7 +236,28 @@
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/get_features_into_CSV.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/get_origin.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Dlib_face_recognition_from_camera" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
@ -234,15 +267,19 @@
<method v="2" /> <method v="2" />
</configuration> </configuration>
<list> <list>
<item itemvalue="Python.get_faces_from_camera" />
<item itemvalue="Python.get_features_into_CSV" />
<item itemvalue="Python.face_reco_from_camera" /> <item itemvalue="Python.face_reco_from_camera" />
<item itemvalue="Python.features_extraction_to_csv" />
<item itemvalue="Python.get_faces_from_camera" />
<item itemvalue="Python.get_origin" />
<item itemvalue="Python.test" />
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.face_reco_from_camera" /> <item itemvalue="Python.face_reco_from_camera" />
<item itemvalue="Python.get_features_into_CSV" /> <item itemvalue="Python.features_extraction_to_csv" />
<item itemvalue="Python.get_faces_from_camera" /> <item itemvalue="Python.get_faces_from_camera" />
<item itemvalue="Python.test" />
<item itemvalue="Python.get_origin" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -260,21 +297,21 @@
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="842" y="68" width="1194" height="987" extended-state="0" /> <frame x="0" y="27" width="1920" height="988" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.28200692" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2090813" />
<window_info id="Structure" order="1" weight="0.25" /> <window_info id="Structure" order="1" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.4976526" /> <window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.25686976" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39952996" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.39952996" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" /> <window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" weight="0.32983682" /> <window_info anchor="bottom" id="Version Control" order="7" weight="0.32983682" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.39976552" /> <window_info anchor="bottom" id="Terminal" order="8" weight="0.28434888" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="bottom" id="Python Console" order="10" /> <window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" /> <window_info anchor="right" id="Commander" order="0" weight="0.4" />
@ -282,9 +319,6 @@
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout> </layout>
</component> </component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
<default-breakpoints> <default-breakpoints>
@ -300,58 +334,59 @@
<entry file="file://$PROJECT_DIR$/use_camera.py" /> <entry file="file://$PROJECT_DIR$/use_camera.py" />
<entry file="file://$PROJECT_DIR$/patch" /> <entry file="file://$PROJECT_DIR$/patch" />
<entry file="file://$PROJECT_DIR$/README.md" /> <entry file="file://$PROJECT_DIR$/README.md" />
<entry file="file://$PROJECT_DIR$/data/data_csvs_from_camera/person_1.csv" />
<entry file="file://$PROJECT_DIR$/data/data_csvs_from_camera/person_2.csv" /> <entry file="file://$PROJECT_DIR$/data/data_csvs_from_camera/person_2.csv" />
<entry file="file://$PROJECT_DIR$/data/data_faces_from_camera/person_6/img_face_1.jpg" /> <entry file="file://$PROJECT_DIR$/data/data_faces_from_camera/person_6/img_face_1.jpg" />
<entry file="file://$PROJECT_DIR$/test.py" />
<entry file="file://$PROJECT_DIR$/data/features_all.csv" />
<entry file="file://$PROJECT_DIR$/introduction/face_reco_single_person_custmize_name.png" /> <entry file="file://$PROJECT_DIR$/introduction/face_reco_single_person_custmize_name.png" />
<entry file="file://$PROJECT_DIR$/how_to_use_camera.py"> <entry file="file://$PROJECT_DIR$/data/data_csvs_from_camera/person_1.csv" />
<provider selected="true" editor-type-id="text-editor"> <entry file="file://$PROJECT_DIR$/get_features_into_CSV.py" />
<state relative-caret-position="513"> <entry file="file://$PROJECT_DIR$/get_origin.py" />
<caret line="27" column="13" selection-start-line="27" selection-start-column="13" selection-end-line="27" selection-end-column="13" /> <entry file="file://$PROJECT_DIR$/test.py" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/get_features_into_CSV.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="83">
<caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="16" />
<folding>
<element signature="e#491#501#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/get_faces_from_camera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="67">
<caret line="12" column="34" selection-start-line="12" selection-start-column="34" selection-end-line="12" selection-end-column="34" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/face_reco_from_camera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="127">
<caret line="89" column="22" lean-forward="true" selection-start-line="89" selection-start-column="22" selection-end-line="89" selection-end-column="22" />
<folding>
<element signature="e#230#264#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/requirements.txt"> <entry file="file://$PROJECT_DIR$/requirements.txt">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76"> <state relative-caret-position="36">
<caret line="4" column="16" lean-forward="true" selection-start-line="4" selection-start-column="16" selection-end-line="4" selection-end-column="16" /> <caret line="2" column="16" selection-start-line="2" selection-start-column="16" selection-end-line="2" selection-end-column="16" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/introduction/face_reco_two_people_in_database.png"> <entry file="file://$PROJECT_DIR$/introduction/face_reco_two_people_in_database.png">
<provider selected="true" editor-type-id="images" /> <provider selected="true" editor-type-id="images" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/how_to_use_camera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="486">
<caret line="27" column="13" selection-start-line="27" selection-start-column="13" selection-end-line="27" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/features_all.csv">
<provider selected="true" editor-type-id="csv-text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/get_faces_from_camera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="309">
<caret line="69" selection-start-line="69" selection-end-line="69" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/features_extraction_to_csv.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="248">
<caret line="73" column="36" selection-start-line="73" selection-start-column="36" selection-end-line="73" selection-end-column="36" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.rst"> <entry file="file://$PROJECT_DIR$/README.rst">
<provider selected="true" editor-type-id="restructured-text-editor" /> <provider selected="true" editor-type-id="restructured-text-editor" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/face_reco_from_camera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="489">
<caret line="160" column="23" lean-forward="true" selection-start-line="160" selection-start-column="23" selection-end-line="160" selection-end-column="23" />
<folding>
<element signature="e#230#264#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component> </component>
</project> </project>

99
README.rst Normal file → Executable file
View File

@ -1,5 +1,5 @@
Face recognition from camera Face recognition from camera with Dlib
############################ ######################################
Introduction Introduction
************ ************
@ -30,12 +30,12 @@ Detect and recognize single/multi-faces from camera;
当多张人脸 / When multi-faces: 当多张人脸 / When multi-faces:
一张已录入人脸 + 未录入 unknown 人脸: 一张已录入人脸 + 未录入 unknown 人脸 / 1x known face + 1x unknown face:
.. image:: introduction/face_reco_two_people.png .. image:: introduction/face_reco_two_people.png
:align: center :align: center
同时识别多张已录入人脸: 同时识别多张已录入人脸 / multi-faces recognition at the same time:
.. image:: introduction/face_reco_two_people_in_database.png .. image:: introduction/face_reco_two_people_in_database.png
:align: center :align: center
@ -55,7 +55,7 @@ Overview
Steps Steps
***** *****
#. 下载源码 / Download from website or via GitHub Desktop in windows, or clone repo in Ubuntu #. 下载源码 / Download zip from website or via GitHub Desktop in windows, or git clone in Ubuntu
.. code-block:: bash .. code-block:: bash
@ -67,13 +67,13 @@ Steps
python3 get_face_from_camera.py python3 get_face_from_camera.py
#. 提取所有录入人脸数据存入 features_all.csv #. 提取所有录入人脸数据存入 features_all.csv / Features extraction and save into features_all.csv
.. code-block:: bash .. code-block:: bash
python3 get_features_into_CSV.py python3 features_extraction_to_csv.py
#. 调用摄像头进行实时人脸识别 #. 调用摄像头进行实时人脸识别 / Real-time face recognition
.. code-block:: bash .. code-block:: bash
@ -83,6 +83,67 @@ Steps
About Source Code About Source Code
***************** *****************
Repo 的 tree / 树状图:
::
.
├── get_faces_from_camera.py # Step1. Faces register
├── features_extraction_to_csv.py # Step2. Features extraction
├── face_reco_from_camera.py # Step3. Faces recognition
├── how_to_use_camera.py # Use the default camera by opencv
├── data
│   ├── data_dlib # Dlib's model
│   │   ├── dlib_face_recognition_resnet_model_v1.dat
│   │   ├── shape_predictor_5_face_landmarks.dat
│   │   └── shape_predictor_68_face_landmarks.dat
│   ├── data_faces_from_camera # Face images captured from camera (will generate after step 1)
│   │   ├── person_1
│   │   │   ├── img_face_1.jpg
│   │   │   └── img_face_2.jpg
│   │   └── person_2
│   │   └── img_face_1.jpg
│   │   └── img_face_2.jpg
│   └── features_all.csv # CSV to save all the features of known faces (will generate after step 2)
├── introduction # Some files for readme.rst
│   ├── Dlib_Face_recognition_by_coneypo.pptx
│   ├── face_reco_single_person_customize_name.png
│   ├── face_reco_single_person.png
│   ├── face_reco_two_people_in_database.png
│   ├── face_reco_two_people.png
│   ├── get_face_from_camera_out_of_range.png
│   ├── get_face_from_camera.png
│   └── overview.png
├── README.rst
└── requirements.txt # Some python packages needed
用到的 Dlib 相关模型函数:
#. Dlib 正向人脸检测器 (based on HOG), output: <class 'dlib.dlib.rectangles'>
.. code-block:: python
detector = dlib.get_frontal_face_detector()
faces = detector(img_gray, 0)
#. Dlib 人脸预测器, output: <class 'dlib.dlib.full_object_detection'>
.. code-block:: python
predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_5_face_landmarks.dat")
shape = predictor(img_rd, faces[i])
#. 特征描述子 Face recognition model, the object maps human faces into 128D vectors
.. code-block:: python
face_rec = dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")
Python 源码介绍如下: Python 源码介绍如下:
#. get_face_from_camera.py: #. get_face_from_camera.py:
@ -93,7 +154,7 @@ Python 源码介绍如下:
* 超出会有 "out of range" 的提醒; * 超出会有 "out of range" 的提醒;
#. get_features_into_CSV.py: #. features_extraction_to_csv.py:
从上一步存下来的图像文件中,提取人脸数据存入CSV; 从上一步存下来的图像文件中,提取人脸数据存入CSV;
@ -108,31 +169,27 @@ Python 源码介绍如下:
* Compare the faces captured from camera with the faces you have registered which are saved in "features_all.csv" * Compare the faces captured from camera with the faces you have registered which are saved in "features_all.csv"
* 将捕获到的人脸数据和之前存的人脸数据进行对比计算欧式距离, 由此判断是否是同一个人; * 将捕获到的人脸数据和之前存的人脸数据进行对比计算欧式距离, 由此判断是否是同一个人;
修改显示的人名 / If you want customize the names shown, please refer to this patch and modify the code: https://github.com/coneypo/Dlib_face_recognition_from_camera/commit/58466ce87bf3a42ac5ef855b791bf8c658d408df?diff=unified
.. image:: introduction/face_reco_single_person_customize_name.png
:align: center
More More
**** ****
Tips: Tips:
1. Windows下建议不要把代码放到 ``C:\``, 可能会出现权限读取问题 #. 如果希望详细了解 dlib 的用法,请参考 Dlib 官方 Python api 的网站 / You can refer to this link for more information of how to use dlib: http://dlib.net/python/index.html
2. 代码最好不要有中文路径 #. Windows下建议不要把代码放到 ``C:\``, 可能会出现权限读取问题 / In windows, we will not recommend that running this repo in dir ``C:\``
3. 人脸录入的时候先建文件夹再保存图片, 先 ``N````S`` #. 代码最好不要有中文路径 / No chinese characters in your code directory
For more details, please refer to my blog (in chinese) or mail to me / #. 人脸录入的时候先建文件夹再保存图片, 先 ``N````S`` / Press ``N`` before ``S``
可以访问我的博客获取本项目的更详细介绍,如有问题可以邮件联系我: 可以访问我的博客获取本项目的更详细介绍,如有问题可以邮件联系我 /
For more details, please refer to my blog (in chinese) or mail to me :
* Blog: https://www.cnblogs.com/AdaminXie/p/9010298.html * Blog: https://www.cnblogs.com/AdaminXie/p/9010298.html
* Mail: coneypo@foxmail.com * Mail: coneypo@foxmail.com ( Dlib 相关 repo 问题请联系 @foxmail 而不是 @intel )
仅限于交流学习, 商业合作勿扰; 仅限于交流学习, 商业合作勿扰;

View File

0
data/data_dlib/shape_predictor_5_face_landmarks.dat Normal file → Executable file
View File

0
data/data_dlib/shape_predictor_68_face_landmarks.dat Normal file → Executable file
View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

56
face_reco_from_camera.py Normal file → Executable file
View File

@ -6,7 +6,7 @@
# GitHub: https://github.com/coneypo/Dlib_face_recognition_from_camera # GitHub: https://github.com/coneypo/Dlib_face_recognition_from_camera
# Created at 2018-05-11 # Created at 2018-05-11
# Updated at 2019-03-23 # Updated at 2019-04-09
import dlib # 人脸处理的库 Dlib import dlib # 人脸处理的库 Dlib
import numpy as np # 数据处理的库 numpy import numpy as np # 数据处理的库 numpy
@ -25,12 +25,7 @@ def return_euclidean_distance(feature_1, feature_2):
feature_1 = np.array(feature_1) feature_1 = np.array(feature_1)
feature_2 = np.array(feature_2) feature_2 = np.array(feature_2)
dist = np.sqrt(np.sum(np.square(feature_1 - feature_2))) dist = np.sqrt(np.sum(np.square(feature_1 - feature_2)))
print("e_distance: ", dist) return dist
if dist > 0.4:
return "diff"
else:
return "same"
# 处理存放所有人脸特征的 csv # 处理存放所有人脸特征的 csv
@ -102,6 +97,7 @@ while cap.isOpened():
# 遍历捕获到的图像中所有的人脸 # 遍历捕获到的图像中所有的人脸
# traversal all the faces in the database # traversal all the faces in the database
for k in range(len(faces)): for k in range(len(faces)):
print("##### camera person", k+1, "#####")
# 让人名跟随在矩形框的下方 # 让人名跟随在矩形框的下方
# 确定人名的位置坐标 # 确定人名的位置坐标
# 先默认所有人不认识,是 unknown # 先默认所有人不认识,是 unknown
@ -113,27 +109,41 @@ while cap.isOpened():
# 对于某张人脸,遍历所有存储的人脸特征 # 对于某张人脸,遍历所有存储的人脸特征
# for every faces detected, compare the faces in the database # for every faces detected, compare the faces in the database
e_distance_list = []
for i in range(len(features_known_arr)): for i in range(len(features_known_arr)):
print("with person_", str(i+1), "the ", end='') # 如果 person_X 数据不为空
# 将某张人脸与存储的所有人脸数据进行比对 if str(features_known_arr[i][0]) != '0.0':
compare = return_euclidean_distance(features_cap_arr[k], features_known_arr[i]) print("with person", str(i + 1), "the e distance: ", end='')
if compare == "same": # 找到了相似脸 e_distance_tmp = return_euclidean_distance(features_cap_arr[k], features_known_arr[i])
# 在这里修改 person_1, person_2 ... 的名字 print(e_distance_tmp)
# 这里只写了前三个 e_distance_list.append(e_distance_tmp)
# 可以在这里改称 Jack, Tom and others else:
# Here you can modify the names shown on the camera # 空数据 person_X
if i == 0: e_distance_list.append(999999999)
name_namelist[k] = "Person 1" # Find the one with minimum e distance
elif i == 1: similar_person_num = e_distance_list.index(min(e_distance_list))
name_namelist[k] = "Person 2" print("Minimum e distance with person", int(similar_person_num)+1)
elif i == 2:
name_namelist[k] = "Person 3" if min(e_distance_list) < 0.4:
# 在这里修改 person_1, person_2 ... 的名字
# 可以在这里改称 Jack, Tom and others
# Here you can modify the names shown on the camera
name_namelist[k] = str("Person "+str(int(similar_person_num)+1))\
.replace("Person 1", "Sherry")\
.replace("Person 2", "Jack")\
.replace("Person 3", "Ronnie")\
.replace("Person 4", "Terry")\
.replace("Person 5", "Wilson")
# print("May be person "+str(int(similar_person_num)+1))
else:
print("Unknown person")
# 矩形框 # 矩形框
# draw rectangle # draw rectangle
for kk, d in enumerate(faces): for kk, d in enumerate(faces):
# 绘制矩形框 # 绘制矩形框
cv2.rectangle(img_rd, tuple([d.left(), d.top()]), tuple([d.right(), d.bottom()]), (0, 255, 255), 2) cv2.rectangle(img_rd, tuple([d.left(), d.top()]), tuple([d.right(), d.bottom()]), (0, 255, 255), 2)
print('\n')
# 在人脸框下面写人脸名字 # 在人脸框下面写人脸名字
# write names under rectangle # write names under rectangle
@ -153,4 +163,4 @@ while cap.isOpened():
cap.release() cap.release()
# 删除建立的窗口 delete all the windows # 删除建立的窗口 delete all the windows
cv2.destroyAllWindows() cv2.destroyAllWindows()

97
features_extraction_to_csv.py Executable file
View File

@ -0,0 +1,97 @@
# 从人脸图像文件中提取人脸特征存入 CSV
# Features extraction from images and save into features_all.csv
# Author: coneypo
# Blog: http://www.cnblogs.com/AdaminXie
# GitHub: https://github.com/coneypo/Dlib_face_recognition_from_camera
# Mail: coneypo@foxmail.com
# Created at 2018-05-11
# Updated at 2019-04-04
import cv2
import os
import dlib
from skimage import io
import csv
import numpy as np
# 要读取人脸图像文件的路径
path_images_from_camera = "data/data_faces_from_camera/"
# Dlib 正向人脸检测器
detector = dlib.get_frontal_face_detector()
# Dlib 人脸预测器
predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_5_face_landmarks.dat")
# Dlib 人脸识别模型
# Face recognition model, the object maps human faces into 128D vectors
face_rec = dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")
# 返回单张图像的 128D 特征
def return_128d_features(path_img):
img_rd = io.imread(path_img)
img_gray = cv2.cvtColor(img_rd, cv2.COLOR_BGR2RGB)
faces = detector(img_gray, 1)
print("%-40s %-20s" % ("检测到人脸的图像 / image with faces detected:", path_img), '\n')
# 因为有可能截下来的人脸再去检测,检测不出来人脸了
# 所以要确保是 检测到人脸的人脸图像 拿去算特征
if len(faces) != 0:
shape = predictor(img_gray, faces[0])
face_descriptor = face_rec.compute_face_descriptor(img_gray, shape)
else:
face_descriptor = 0
print("no face")
return face_descriptor
# 将文件夹中照片特征提取出来, 写入 CSV
def return_features_mean_personX(path_faces_personX):
features_list_personX = []
photos_list = os.listdir(path_faces_personX)
if photos_list:
for i in range(len(photos_list)):
# 调用return_128d_features()得到128d特征
print("%-40s %-20s" % ("正在读的人脸图像 / image to read:", path_faces_personX + "/" + photos_list[i]))
features_128d = return_128d_features(path_faces_personX + "/" + photos_list[i])
# print(features_128d)
# 遇到没有检测出人脸的图片跳过
if features_128d == 0:
i += 1
else:
features_list_personX.append(features_128d)
else:
print("文件夹内图像文件为空 / Warning: No images in " + path_faces_personX + '/', '\n')
# 计算 128D 特征的均值
# personX 的 N 张图像 x 128D -> 1 x 128D
if features_list_personX:
features_mean_personX = np.array(features_list_personX).mean(axis=0)
else:
features_mean_personX = '0'
return features_mean_personX
# 获取已录入的最后一个人脸序号 / get the num of latest person
person_list = os.listdir("data/data_faces_from_camera/")
person_num_list = []
for person in person_list:
person_num_list.append(int(person.split('_')[-1]))
person_cnt = max(person_num_list)
with open("data/features_all.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
for person in range(person_cnt):
# Get the mean/average features of face/personX, it will be a list with a length of 128D
print(path_images_from_camera + "person_"+str(person+1))
features_mean_personX = return_features_mean_personX(path_images_from_camera + "person_"+str(person+1))
writer.writerow(features_mean_personX)
print("特征均值 / The mean of features:", list(features_mean_personX))
print('\n')
print("所有录入人脸数据存入 / Save all the features of faces registered into: data/features_all.csv")

45
get_faces_from_camera.py Normal file → Executable file
View File

@ -7,7 +7,7 @@
# Mail: coneypo@foxmail.com # Mail: coneypo@foxmail.com
# Created at 2018-05-11 # Created at 2018-05-11
# Updated at 2019-03-23 # Updated at 2019-04-12
import dlib # 人脸处理的库 Dlib import dlib # 人脸处理的库 Dlib
import numpy as np # 数据处理的库 Numpy import numpy as np # 数据处理的库 Numpy
@ -34,9 +34,8 @@ cnt_ss = 0
# 存储人脸的文件夹 the folder to save faces # 存储人脸的文件夹 the folder to save faces
current_face_dir = "" current_face_dir = ""
# 保存 photos/csv 的路径 the directory to save photos/csv # 保存 faces images 的路径 the directory to save images of faces
path_photos_from_camera = "data/data_faces_from_camera/" path_photos_from_camera = "data/data_faces_from_camera/"
path_csv_from_photos = "data/data_csvs_from_camera/"
# 新建保存人脸图像文件和数据CSV文件夹 # 新建保存人脸图像文件和数据CSV文件夹
@ -48,10 +47,6 @@ def pre_work_mkdir():
pass pass
else: else:
os.mkdir(path_photos_from_camera) os.mkdir(path_photos_from_camera)
if os.path.isdir(path_csv_from_photos):
pass
else:
os.mkdir(path_csv_from_photos)
pre_work_mkdir() pre_work_mkdir()
@ -67,25 +62,25 @@ def pre_work_del_old_face_folders():
for i in range(len(folders_rd)): for i in range(len(folders_rd)):
shutil.rmtree(path_photos_from_camera+folders_rd[i]) shutil.rmtree(path_photos_from_camera+folders_rd[i])
csv_rd = os.listdir(path_csv_from_photos) if os.path.isfile("data/features_all.csv"):
for i in range(len(csv_rd)): os.remove("data/features_all.csv")
os.remove(path_csv_from_photos+csv_rd[i])
# 这里在每次程序录入之前, 删掉之前存的人脸数据 # 这里在每次程序录入之前, 删掉之前存的人脸数据
# 如果这里打开,每次进行人脸录入的时候都会删掉之前的人脸图像文件夹 # 如果这里打开,每次进行人脸录入的时候都会删掉之前的人脸图像文件夹 person_1/,person_2/,person_3/...
# If enable this function, it will delete all the old data in dir person_1/,person_2/,/person_3/...
# pre_work_del_old_face_folders() # pre_work_del_old_face_folders()
################################## ##################################
# 如果有之前录入的人脸 # 如果有之前录入的人脸 / if the old folders exists
# 在之前 person_x 的序号按照 person_x+1 开始录入 # 在之前 person_x 的序号按照 person_x+1 开始录入 / start from person_x+1
# if old face exists, start from person_x+1
if os.listdir("data/data_faces_from_camera/"): if os.listdir("data/data_faces_from_camera/"):
# 获取已录入的最后一个人脸序号 # 获取已录入的最后一个人脸序号 / get the num of latest person
person_list = os.listdir("data/data_faces_from_camera/") person_list = os.listdir("data/data_faces_from_camera/")
person_list.sort() person_num_list = []
person_num_latest = int(str(person_list[-1]).split("_")[-1]) for person in person_list:
person_cnt = person_num_latest person_num_list.append(int(person.split('_')[-1]))
person_cnt = max(person_num_list)
# 如果第一次存储或者没有之前录入的人脸, 按照 person_1 开始录入 # 如果第一次存储或者没有之前录入的人脸, 按照 person_1 开始录入
# start from person_1 # start from person_1
@ -99,8 +94,10 @@ save_flag = 1
press_n_flag = 0 press_n_flag = 0
while cap.isOpened(): while cap.isOpened():
# 480 height * 640 width
flag, img_rd = cap.read() flag, img_rd = cap.read()
# print(img_rd.shape)
# It should be 480 height * 640 width
kk = cv2.waitKey(1) kk = cv2.waitKey(1)
img_gray = cv2.cvtColor(img_rd, cv2.COLOR_RGB2GRAY) img_gray = cv2.cvtColor(img_rd, cv2.COLOR_RGB2GRAY)
@ -124,8 +121,7 @@ while cap.isOpened():
# 检测到人脸 / if face detected # 检测到人脸 / if face detected
if len(faces) != 0: if len(faces) != 0:
# 矩形框 # 矩形框 / show the rectangle box
# show the rectangle box
for k, d in enumerate(faces): for k, d in enumerate(faces):
# 计算矩形大小 # 计算矩形大小
# we need to compute the width and height of the box # we need to compute the width and height of the box
@ -142,10 +138,14 @@ while cap.isOpened():
# 设置颜色 / the color of rectangle of faces detected # 设置颜色 / the color of rectangle of faces detected
color_rectangle = (255, 255, 255) color_rectangle = (255, 255, 255)
# 判断人脸矩形框是否超出 480x640
if (d.right()+ww) > 640 or (d.bottom()+hh > 480) or (d.left()-ww < 0) or (d.top()-hh < 0): if (d.right()+ww) > 640 or (d.bottom()+hh > 480) or (d.left()-ww < 0) or (d.top()-hh < 0):
cv2.putText(img_rd, "OUT OF RANGE", (20, 300), font, 0.8, (0, 0, 255), 1, cv2.LINE_AA) cv2.putText(img_rd, "OUT OF RANGE", (20, 300), font, 0.8, (0, 0, 255), 1, cv2.LINE_AA)
color_rectangle = (0, 0, 255) color_rectangle = (0, 0, 255)
save_flag = 0 save_flag = 0
if kk == ord('s'):
print("请调整位置 / Please adjust your position")
else: else:
color_rectangle = (255, 255, 255) color_rectangle = (255, 255, 255)
save_flag = 1 save_flag = 1
@ -157,8 +157,7 @@ while cap.isOpened():
# 根据人脸大小生成空的图像 / create blank image according to the size of face detected # 根据人脸大小生成空的图像 / create blank image according to the size of face detected
im_blank = np.zeros((int(height*2), width*2, 3), np.uint8) im_blank = np.zeros((int(height*2), width*2, 3), np.uint8)
save_flag = 1;
if save_flag: if save_flag:
# 按下 's' 保存摄像头中的人脸到本地 / press 's' to save faces into local images # 按下 's' 保存摄像头中的人脸到本地 / press 's' to save faces into local images
if kk == ord('s'): if kk == ord('s'):

View File

@ -1,137 +0,0 @@
# 从人脸图像文件中提取人脸特征存入 CSV
# Get features from images and save into features_all.csv
# Author: coneypo
# Blog: http://www.cnblogs.com/AdaminXie
# GitHub: https://github.com/coneypo/Dlib_face_recognition_from_camera
# Mail: coneypo@foxmail.com
# Created at 2018-05-11
# Updated at 2019-02-25
# 增加录入多张人脸到 CSV 的功能
# return_128d_features() 获取某张图像的 128D 特征
# write_into_csv() 获取某个路径下所有图像的特征,并写入 CSV
# compute_the_mean() 从 CSV 中读取 128D 特征,并计算特征均值
import cv2
import os
import dlib
from skimage import io
import csv
import numpy as np
import pandas as pd
# 要读取人脸图像文件的路径
path_photos_from_camera = "data/data_faces_from_camera/"
# 储存人脸特征 csv 的路径
path_csv_from_photos = "data/data_csvs_from_camera/"
# Dlib 正向人脸检测器
detector = dlib.get_frontal_face_detector()
# Dlib 人脸预测器
predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_5_face_landmarks.dat")
# Dlib 人脸识别模型
# Face recognition model, the object maps human faces into 128D vectors
facerec = dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")
# 返回单张图像的 128D 特征
def return_128d_features(path_img):
img = io.imread(path_img)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
faces = detector(img_gray, 1)
print("%-40s %-20s" % ("检测到人脸的图像 / image with faces detected:", path_img), '\n')
# 因为有可能截下来的人脸再去检测,检测不出来人脸了
# 所以要确保是 检测到人脸的人脸图像 拿去算特征
if len(faces) != 0:
shape = predictor(img_gray, faces[0])
face_descriptor = facerec.compute_face_descriptor(img_gray, shape)
else:
face_descriptor = 0
print("no face")
# print(face_descriptor)
return face_descriptor
# 将文件夹中照片特征提取出来, 写入 CSV
# path_faces_personX: 图像文件夹的路径
# path_csv_from_photos: 要生成的 CSV 路径
def write_into_csv(path_faces_personX, path_csv_from_photos):
photos_list = os.listdir(path_faces_personX)
with open(path_csv_from_photos, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
if photos_list:
for i in range(len(photos_list)):
# 调用return_128d_features()得到128d特征
print("%-40s %-20s" % ("正在读的人脸图像 / image to read:", path_faces_personX + "/" + photos_list[i]))
features_128d = return_128d_features(path_faces_personX + "/" + photos_list[i])
# print(features_128d)
# 遇到没有检测出人脸的图片跳过
if features_128d == 0:
i += 1
else:
writer.writerow(features_128d)
else:
print("文件夹内图像文件为空 / Warning: Empty photos in " + path_faces_personX + '/', '\n')
writer.writerow("")
# 读取某人所有的人脸图像的数据,写入 person_X.csv
faces = os.listdir(path_photos_from_camera)
faces.sort()
for person in faces:
print("##### " + person + " #####")
print(path_csv_from_photos + person + ".csv")
write_into_csv(path_photos_from_camera + person, path_csv_from_photos + person + ".csv")
print('\n')
# 从 CSV 中读取数据,计算 128D 特征的均值
def compute_the_mean(path_csv_from_photos):
column_names = []
# 128D 特征
for feature_num in range(128):
column_names.append("features_" + str(feature_num + 1))
# 利用 pandas 读取 csv
rd = pd.read_csv(path_csv_from_photos, names=column_names)
if rd.size != 0:
# 存放 128D 特征的均值
feature_mean_list = []
for feature_num in range(128):
tmp_arr = rd["features_" + str(feature_num + 1)]
tmp_arr = np.array(tmp_arr)
# 计算某一个特征的均值
tmp_mean = np.mean(tmp_arr)
feature_mean_list.append(tmp_mean)
else:
feature_mean_list = []
return feature_mean_list
# 存放所有特征均值的 CSV 的路径
path_csv_from_photos_feature_all = "data/features_all.csv"
# 存放人脸特征的 CSV 的路径
path_csv_from_photos = "data/data_csvs_from_camera/"
with open(path_csv_from_photos_feature_all, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
csv_rd = os.listdir(path_csv_from_photos)
csv_rd.sort()
print("##### 得到的特征均值 / The generated average values of features stored in: #####")
for i in range(len(csv_rd)):
feature_mean_list = compute_the_mean(path_csv_from_photos + csv_rd[i])
print(path_csv_from_photos + csv_rd[i])
writer.writerow(feature_mean_list)

0
how_to_use_camera.py Normal file → Executable file
View File

BIN
introduction/Dlib_Face_recognition_by_coneypo.pptx Normal file → Executable file

Binary file not shown.

0
introduction/face_reco_single_person.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 428 KiB

After

Width:  |  Height:  |  Size: 428 KiB

View File

Before

Width:  |  Height:  |  Size: 457 KiB

After

Width:  |  Height:  |  Size: 457 KiB

0
introduction/face_reco_two_people.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 499 KiB

After

Width:  |  Height:  |  Size: 499 KiB

0
introduction/face_reco_two_people_in_database.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 425 KiB

After

Width:  |  Height:  |  Size: 425 KiB

0
introduction/get_face_from_camera.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 416 KiB

After

Width:  |  Height:  |  Size: 416 KiB

0
introduction/get_face_from_camera_out_of_range.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 433 KiB

After

Width:  |  Height:  |  Size: 433 KiB

BIN
introduction/overview.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 445 KiB

After

Width:  |  Height:  |  Size: 324 KiB

4
requirements.txt Normal file → Executable file
View File

@ -1,5 +1,3 @@
dlib==19.17.0 dlib==19.17.0
numpy==1.15.1 numpy==1.15.1
opencv-python==4.0.0.21 scikit-image==0.14.0
pandas==0.23.4
scikit-image==0.14.0