Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2018 02:16
Show Gist options
  • Save anonymous/1419c9e86e6cabf1572ff006769e68df to your computer and use it in GitHub Desktop.
Save anonymous/1419c9e86e6cabf1572ff006769e68df to your computer and use it in GitHub Desktop.
Car Plates Detection of Multiple Photos
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import os\nimport subprocess as subp\nimport numpy as np\nimport pandas as pd",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "os.chdir(\"/Users/bernardo/Dropbox (ID)/CM Data Science/Car Photos\")\npath = (\"/Users/bernardo/Dropbox (ID)/CM Data Science/Car Photos/Images/Originals/\")\nfiles = [f for f in os.listdir(path) if f.endswith('.jpg')]\n\nresponse = []\nfor j in range(len(files)):\n image = files[j]\n x = subp.run([\"cd /Users/bernardo/Dropbox\\ \\(ID\\)/CM\\ Data\\ Science/Car\\ Photos/Images/Originals/; alpr \" + image], shell=True, check=True, stdout=subp.PIPE)\n x = x.stdout.decode().split('- ')[1:6]\n if len(x) > 0:\n plates = []\n for i in range(len(x)): \n plates.append(x[i][0:6])\n response.append((image, plates))\n if j in np.arange(1, len(files), 200):\n print(j)",
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": "1\n201\n401\n601\n801\n1001\n1201\n1401\n1601\n1801\n2001\n2201\n2401\n2601\n2801\n3001\n3201\n3401\n3601\n3801\n4001\n4201\n4401\n4601\n4801\n5001\n5201\n5401\n5601\n5801\n6001\n6201\n6401\n6601\n6801\n7001\n7201\n7401\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df = pd.DataFrame(response, columns = ['file','plates'])\ndf[['plate1','plate2','plate3','plate4','plate5']] = pd.DataFrame(df.plates.values.tolist(), index= df.index)\ndf = df.drop('plates', 1)\ndf.to_csv(\"Data/files_plates.csv\")",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.sample(10)",
"execution_count": 14,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 14,
"data": {
"text/plain": " file plate1 plate2 \\\n736 mercedes-benz-a200-especial-con-interior-y-sil... HSR6Z2 HSR622 \n564 nissan-march-2013-D_NQ_NP_749700-MCO2662402602... JR964\\t MJR964 \n693 ford-escape-D_NQ_NP_707049-MCO26924609514_0220... HS045\\t HSO45\\t \n274 chevrolet-captiva-sport-36-awd-2010-todo-al-di... REU37\\t REU374 \n104 chevrolet-cruze-hb-D_NQ_NP_826438-MCO269191778... HAS801 HAS8O1 \n602 renault-twingo-D_NQ_NP_788672-MCO26930480240_0... BHL780 BHL78Q \n420 chery-tiggo-D_NQ_NP_611777-MCO26936736111_0320... JER840 JER84O \n747 mazda-mazda-2-iyn034-D_NQ_NP_952434-MCO2692540... IYN034 IYN0S4 \n218 hyundai-tucson-ix-35-D_NQ_NP_614944-MCO2664199... RH868\\t RHM868 \n796 chevrolet-optra-D_NQ_NP_609631-MCO26912616094_... DAH317 QAH317 \n\n plate3 plate4 plate5 \n736 HSR6ZZ HSR62Z H8R6Z2 \n564 HJR964 JR96\\t NJR964 \n693 HS04S\\t HSQ45\\t HIS045 \n274 RE037\\t REO37\\t REQ37\\t \n104 HAS80I HAS8Q1 HAS8D1 \n602 BHL80\\t BHL78O BHL8Q\\t \n420 JER84Q JER80\\t JER84D \n747 IYNO34 IYNQ34 IYND34 \n218 RH86B\\t RHB68\\t RHN868 \n796 0AH317 OAH317 BAH317 ",
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>file</th>\n <th>plate1</th>\n <th>plate2</th>\n <th>plate3</th>\n <th>plate4</th>\n <th>plate5</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>736</th>\n <td>mercedes-benz-a200-especial-con-interior-y-sil...</td>\n <td>HSR6Z2</td>\n <td>HSR622</td>\n <td>HSR6ZZ</td>\n <td>HSR62Z</td>\n <td>H8R6Z2</td>\n </tr>\n <tr>\n <th>564</th>\n <td>nissan-march-2013-D_NQ_NP_749700-MCO2662402602...</td>\n <td>JR964\\t</td>\n <td>MJR964</td>\n <td>HJR964</td>\n <td>JR96\\t</td>\n <td>NJR964</td>\n </tr>\n <tr>\n <th>693</th>\n <td>ford-escape-D_NQ_NP_707049-MCO26924609514_0220...</td>\n <td>HS045\\t</td>\n <td>HSO45\\t</td>\n <td>HS04S\\t</td>\n <td>HSQ45\\t</td>\n <td>HIS045</td>\n </tr>\n <tr>\n <th>274</th>\n <td>chevrolet-captiva-sport-36-awd-2010-todo-al-di...</td>\n <td>REU37\\t</td>\n <td>REU374</td>\n <td>RE037\\t</td>\n <td>REO37\\t</td>\n <td>REQ37\\t</td>\n </tr>\n <tr>\n <th>104</th>\n <td>chevrolet-cruze-hb-D_NQ_NP_826438-MCO269191778...</td>\n <td>HAS801</td>\n <td>HAS8O1</td>\n <td>HAS80I</td>\n <td>HAS8Q1</td>\n <td>HAS8D1</td>\n </tr>\n <tr>\n <th>602</th>\n <td>renault-twingo-D_NQ_NP_788672-MCO26930480240_0...</td>\n <td>BHL780</td>\n <td>BHL78Q</td>\n <td>BHL80\\t</td>\n <td>BHL78O</td>\n <td>BHL8Q\\t</td>\n </tr>\n <tr>\n <th>420</th>\n <td>chery-tiggo-D_NQ_NP_611777-MCO26936736111_0320...</td>\n <td>JER840</td>\n <td>JER84O</td>\n <td>JER84Q</td>\n <td>JER80\\t</td>\n <td>JER84D</td>\n </tr>\n <tr>\n <th>747</th>\n <td>mazda-mazda-2-iyn034-D_NQ_NP_952434-MCO2692540...</td>\n <td>IYN034</td>\n <td>IYN0S4</td>\n <td>IYNO34</td>\n <td>IYNQ34</td>\n <td>IYND34</td>\n </tr>\n <tr>\n <th>218</th>\n <td>hyundai-tucson-ix-35-D_NQ_NP_614944-MCO2664199...</td>\n <td>RH868\\t</td>\n <td>RHM868</td>\n <td>RH86B\\t</td>\n <td>RHB68\\t</td>\n <td>RHN868</td>\n </tr>\n <tr>\n <th>796</th>\n <td>chevrolet-optra-D_NQ_NP_609631-MCO26912616094_...</td>\n <td>DAH317</td>\n <td>QAH317</td>\n <td>0AH317</td>\n <td>OAH317</td>\n <td>BAH317</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"_draft": {
"nbviewer_url": "https://gist.github.com/2533df9b173ab08dfb17b66f164188c3"
},
"gist": {
"id": "2533df9b173ab08dfb17b66f164188c3",
"data": {
"description": "Car Plates Detection of Multiple Photos",
"public": true
}
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.3",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment