├── README.md
├── 国内城市天气查询
├── result.txt
└── weather.py
├── 国内节假日查询
├── datetype.py
└── result.txt
├── 地理坐标距离计算
└── GeoCoortoDistance.py
├── 地理编码
├── geocode.py
└── result.csv
├── 地理逆编码
├── regeocoder.py
└── result.csv
├── 坐标系转换
└── CoorChange.py
└── 车辆图片识别车型
├── result.txt
├── vehicle_model.py
└── 样本车辆.jpg
/README.md:
--------------------------------------------------------------------------------
1 | ## 实用Python脚本
2 | 版本:Python3.6
3 | 包含一些实用的Python脚本,比如天气查询、地理编码、节假日查询、车辆信息查询等等
4 |
5 | 免费API:
6 | [节假日查询](http://api.goseek.cn/)、[城市天气查询](https://www.apiopen.top/weatherApi?city=)、[地理编码](http://api.map.baidu.com)
7 | 、[阿凡达数据](https://www.avatardata.cn/)
8 |
9 | 项目:
10 | 1. [国内城市天气查询](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E5%9B%BD%E5%86%85%E5%9F%8E%E5%B8%82%E5%A4%A9%E6%B0%94%E6%9F%A5%E8%AF%A2)
11 | 2. [国内节假日查询](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E5%9B%BD%E5%86%85%E8%8A%82%E5%81%87%E6%97%A5%E6%9F%A5%E8%AF%A2)
12 | 3. [地理坐标距离计算](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E5%9C%B0%E7%90%86%E5%9D%90%E6%A0%87%E8%B7%9D%E7%A6%BB%E8%AE%A1%E7%AE%97)
13 | 4. [地理编码](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E5%9C%B0%E7%90%86%E7%BC%96%E7%A0%81)
14 | 5. [地理逆编码](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E5%9C%B0%E7%90%86%E9%80%86%E7%BC%96%E7%A0%81)
15 | 6. [坐标系转换](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E5%9D%90%E6%A0%87%E7%B3%BB%E8%BD%AC%E6%8D%A2)
16 | 7. [车辆图片识别车型](https://github.com/hi-weijun/Useful-Python-Script/tree/master/%E8%BD%A6%E8%BE%86%E5%9B%BE%E7%89%87%E8%AF%86%E5%88%AB%E8%BD%A6%E5%9E%8B)
17 |
18 |
19 | 
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/国内城市天气查询/result.txt:
--------------------------------------------------------------------------------
1 | 城市: 上海
2 | 温度: 28 ℃
3 | 提醒: 各项气象条件适宜,无明显降温过程,发生感冒机率较低。
4 | --------------------------以下详细天气--------------------------------
5 | 日期 高温 低温 类型 风力 风向
6 | 0 10日星期一 29℃ 20℃ 小雨 4级 东北风
7 | 1 11日星期二 29℃ 21℃ 多云 4级 东北风
8 | 2 12日星期三 28℃ 20℃ 多云 4级 东南风
9 | 3 13日星期四 28℃ 22℃ 阴 4级 东南风
10 | 4 14日星期五 29℃ 22℃ 多云 4级 东北风
11 |
--------------------------------------------------------------------------------
/国内城市天气查询/weather.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | import json
3 | import time
4 | from urllib import request
5 | from urllib.parse import quote
6 | import pandas as pd
7 |
8 | def goseek(placeName):
9 | text = quote(placeName, 'utf-8')
10 | server_url = 'https://www.apiopen.top/weatherApi?city=' + text
11 | vop_response = request.urlopen(server_url)
12 | x = json.loads(vop_response.read().decode('utf-8'))['data']
13 | print('城市:', x['city'])
14 | print('温度:', x['wendu'],'℃')
15 | print('提醒:', x['ganmao'])
16 | n = 0
17 | for i in x['forecast']:
18 | if n == 0:
19 | # i.keys() = ['日期','高温','风力','低温','风向','类型']
20 | df = pd.DataFrame(i, index=['指标'])
21 | df_all = df
22 | else:
23 | df = pd.DataFrame(i, index=['指标'])
24 | df_all = df_all.append(df)
25 | n += 1
26 | df_all.reset_index(inplace=True, drop=True)
27 | df_all.columns = ['日期', '高温', '风力', '低温', '风向', '类型']
28 | df_all = df_all[['日期', '高温', '低温', '类型', '风力', '风向']]
29 | df_all['高温'] = df_all['高温'].apply(lambda x: x[2:])
30 | df_all['低温'] = df_all['低温'].apply(lambda x: x[2:])
31 | df_all['风力'] = df_all['风力'].apply(lambda x: x[-5:-3])
32 | print('--------------------------以下详细天气--------------------------------')
33 | print(df_all)
34 |
35 | if __name__ == '__main__':
36 | start_time = time.time()
37 | goseek('上海')
38 | stop_time = time.time()
39 | print('run time is %s' % (stop_time - start_time))
40 |
--------------------------------------------------------------------------------
/国内节假日查询/datetype.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | import json
3 | import datetime
4 | import time
5 | from urllib import request
6 |
7 | def goseek(start_date,end_date):
8 | # 参数分别代表需要查询的起始日期和终止日期
9 | start = start_date
10 | end = end_date
11 | datestart = datetime.datetime.strptime(start, '%Y-%m-%d')
12 | dateend = datetime.datetime.strptime(end, '%Y-%m-%d')
13 | server_url = 'http://api.goseek.cn/Tools/holiday?date='
14 | num = 0
15 | while datestart < dateend:
16 | num += 1
17 | datestart += datetime.timedelta(days=1)
18 | date = datestart.strftime('%Y%m%d')
19 | vop_response = request.urlopen(server_url + date)
20 | vop_data= json.loads(vop_response.read().decode('utf-8'))
21 | # 0代表工作日,1代表节假日,2代表调休补班,3代表休息日
22 | if vop_data['data'] == 0:
23 | print(date,vop_data['data'],'工作日')
24 | elif vop_data['data'] == 1:
25 | print(date,vop_data['data'],'节假日')
26 | elif vop_data['data'] == 2:
27 | print(date,vop_data['data'],'调休补班')
28 | elif vop_data['data'] == 3:
29 | print(date,vop_data['data'],'休息日')
30 | else:
31 | print('Error')
32 | print("process is over")
33 | print("run number is %s" % num)
34 | if __name__ == '__main__':
35 | start_time = time.time()
36 | goseek('2019-06-01','2019-12-31')
37 | stop_time = time.time()
38 | print('run time is %s' % (stop_time - start_time))
39 |
--------------------------------------------------------------------------------
/国内节假日查询/result.txt:
--------------------------------------------------------------------------------
1 | 20190602 3 休息日
2 | 20190603 0 工作日
3 | 20190604 0 工作日
4 | 20190605 0 工作日
5 | 20190606 0 工作日
6 | 20190607 1 节假日
7 | 20190608 1 节假日
8 | 20190609 1 节假日
9 | 20190610 0 工作日
10 | 20190611 0 工作日
11 | 20190612 0 工作日
12 | 20190613 0 工作日
13 | 20190614 0 工作日
14 | 20190615 3 休息日
15 | 20190616 3 休息日
16 | 20190617 0 工作日
17 | 20190618 0 工作日
18 | 20190619 0 工作日
19 | 20190620 0 工作日
20 |
--------------------------------------------------------------------------------
/地理坐标距离计算/GeoCoortoDistance.py:
--------------------------------------------------------------------------------
1 | '''
2 | auther:zhu weijun
3 | content:计算两坐标之间的空间距离
4 | '''
5 |
6 | # 方法一,使用geopy库
7 | from geopy.distance import geodesic
8 |
9 | def corrtodistance(lat_1,lon_1,lat_2,lon_2):
10 | # lat:纬度值,lon:经度值
11 | coor1 = (lat_1,lon_1)
12 | coor2 = (lat_2,lon_2)
13 | distance = geodesic(coor1,coor2).km
14 | return distance
15 |
16 | '''
17 | 示例:
18 | 上海虹桥火车站(31.204927,121.343656)
19 | 南京南站(31.975614,118.805403)
20 | 百度地图拾取:两地距离255.7km
21 |
22 | d = corrtodistance(31.204927,121.343656,31.975614,118.805403)
23 | print(d)
24 |
25 | 输出:255.606
26 | '''
27 |
--------------------------------------------------------------------------------
/地理编码/geocode.py:
--------------------------------------------------------------------------------
1 | from urllib import parse
2 | from urllib.request import urlopen
3 | import hashlib
4 | import json
5 | import pandas as pd
6 |
7 | def get_urt(addtress):
8 | #输入你的秘钥,获取地址http://lbsyun.baidu.com/apiconsole/key/create
9 | your_ak = '你的sk'
10 | queryStr = '/geocoder/v2/?address=%s&output=json&ak=your_ak' % addtress
11 | # 对queryStr进行转码,safe内的保留字符不转换
12 | encodedStr = parse.quote(queryStr, safe="/:=&?#+!$,;'@()*[]")
13 | #计算sn
14 | sn = (hashlib.md5(parse.quote_plus(rawStr).encode("utf8")).hexdigest())
15 | #由于URL里面含有中文,所以需要用parse.quote进行处理,然后返回最终可调用的url
16 | url = parse.quote("http://api.map.baidu.com"+queryStr+"&sn="+sn, safe="/:=&?#+!$,;'@()*[]")
17 | response = urlopen(url).read().decode('utf-8')
18 | # print(response)
19 | #将返回的数据转化成json格式
20 | responseJson = json.loads(response)
21 | #获取经纬度
22 | lon = responseJson.get('result')['location']['lng']
23 | lat = responseJson.get('result')['location']['lat']
24 | # status = responseJson.get('status')
25 | #获取误差范围
26 | confidence = responseJson.get('result')['confidence']
27 | #获取地区等级
28 | level = responseJson.get('result')['confidence']
29 | data = pd.DataFrame(data = [[addtress,lon,lat,confidence,level]],columns=['地名','经度','纬度','误差(米)','地区等级'])
30 |
31 | data.to_csv('goeinfo.csv',mode='a',index=False,header=False)
32 | return data
33 | if __name__ == '__main__':
34 | #加载地区名,这里放在tuple里,也可以从csv等文件读取
35 | places = ('黄浦区','徐汇区','长宁区','静安区','普陀区','虹口区','杨浦区','宝山区','闵行区','嘉定区','浦东新区','松江区','金山区','青浦区','奉贤区','崇明区')
36 | with open('goeinfo.csv', 'a+',encoding='utf-8') as f:
37 | f.write("地名,经度,纬度,误差(米),地区等级\n", )
38 | f.close()
39 | for i in places:
40 | get_urt(i)
41 | print('地区加载完成,已生成结果')
42 |
--------------------------------------------------------------------------------
/地理编码/result.csv:
--------------------------------------------------------------------------------
1 | 地名,经度,纬度,误差(米),地区等级
2 | 黄浦区,121.49158559252436,31.23724715206362,25,25
3 | 徐汇区,121.44339635276381,31.194556772822725,18,18
4 | 长宁区,121.43045437545099,31.226847968225428,18,18
5 | 静安区,121.45343177276851,31.233844930401652,20,20
6 | 普陀区,121.40356934916508,31.254973368279597,18,18
7 | 虹口区,121.51158645453457,31.269746698931357,25,25
8 | 杨浦区,121.53251993732523,31.265524144657057,18,18
9 | 宝山区,131.40737518857432,46.58359834024085,16,16
10 | 闵行区,121.38861193361008,31.118842580087428,16,16
11 | 嘉定区,121.27259505835202,31.3801553396772,16,16
12 | 浦东新区,121.55045460683195,31.227348292436346,14,14
13 | 松江区,121.23447959624146,31.037135176464492,16,16
14 | 金山区,121.34848004512126,30.747852376570318,16,16
15 | 青浦区,121.13055310467274,31.155454317980737,16,16
16 | 奉贤区,121.48050373643107,30.923720110285377,16,16
17 | 崇明区,121.40355686271847,31.62856998440405,14,14
18 |
--------------------------------------------------------------------------------
/地理逆编码/regeocoder.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | import json
3 | import pandas as pd
4 | from urllib import request
5 | import re
6 | from urllib.parse import quote
7 |
8 | def goseek(lat,lon):
9 | # 输入你的秘钥,获取地址http://lbsyun.baidu.com/apiconsole/key/create
10 | your_ak = '你的ak'
11 | url = 'http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&extensions_town=true&location={},{}&output=json&pois=1&latest_admin=1&ak={}'.format(lat,lon,your_ak)
12 | rp = request.urlopen(url).read().decode('utf-8')
13 | rp = re.findall(r"\((.*)\)",rp)[0]
14 | rpjson= json.loads(rp)
15 | # 经纬度
16 | lon = rpjson['result']['location']['lng']
17 | lat = rpjson['result']['location']['lat']
18 | # 国家
19 | country = rpjson['result']['addressComponent']['country']
20 | # 省份
21 | province = rpjson['result']['addressComponent']['province']
22 | # 城市
23 | city = rpjson['result']['addressComponent']['city']
24 | # 区县
25 | district = rpjson['result']['addressComponent']['district']
26 | # 乡镇
27 | town = rpjson['result']['addressComponent']['town']
28 | # 描述
29 | desc = rpjson['result']['sematic_description']
30 | # pois
31 | pois = rpjson['result']['pois']
32 |
33 | print('经纬度:',lon,lat)
34 | print('国家:',country)
35 | print('省:',province)
36 | print('市:',city)
37 | print('区县:',district)
38 | print('乡镇:',town)
39 | print('描述:',desc)
40 | num = 1
41 | pois_file = []
42 | for poi in pois:
43 | print('pois')
44 | print(num,poi['name'],poi['tag'])
45 | pois_file.append(poi['name'])
46 | num+=1
47 | print('---------------------------------')
48 | data = pd.DataFrame([[lon, lat, country, province, city, district, town, desc, pois_file]], columns=range(9))
49 | data.to_csv('goeinfo.csv', mode='a', index=False, header=False)
50 |
51 |
52 | if __name__ == '__main__':
53 | with open('goeinfo.csv', 'a+',encoding='utf-8') as f:
54 | f.write("经度,纬度,国家,省份,城市,区县,乡镇,描述,pois\n")
55 | coors = ((31.22874037307247,121.47298325512693),(31.22206126567911,121.5394162080078),(31.161340496865517,121.43847931835936))
56 | for i in coors:
57 | goseek(i[0],i[1])
58 |
--------------------------------------------------------------------------------
/地理逆编码/result.csv:
--------------------------------------------------------------------------------
1 | 经度,纬度,国家,省份,城市,区县,乡镇,描述,pois
2 | 121.47298325512686,31.228740239277148,中国,上海市,上海市,黄浦区,瑞金二路街道,鑫兴大厦附近23米,"['鑫兴大厦', '山阳经济区', '延中公园-南区', '紫勋雍邸', '上海海悦银滩双层LOFT醉美海景房普通公寓分店', '延中广场公园春之园', '福海里', '御花园酒店(淮海中路店)', '春泽中医', '慧公馆(巨鹿路店)']"
3 | 121.53941620800772,31.22206113101506,中国,上海市,上海市,浦东新区,塘桥街道,"陆家嘴软件园内,开伦鑫座附近29米","['陆家嘴软件园', '开伦鑫座', '利华大厦', '伟泰大厦', '上海市申信信息技术专修学院', '金牛大厦', '棒!约翰(上海峨山路店)', '金牛大厦-北楼', '陆家嘴金融信息服务产业基地', '东方路窗帘城']"
4 | 121.43847931835927,31.161340355006345,中国,上海市,上海市,徐汇区,漕河泾街道,上海南站东北382米,"['上海南站', '上海南站(地铁站)', '中国邮政(上海南站邮件转运站)', '上海长途客运南站', '上海万科南站商务城-一期', '三生中国健康产业上海分公司', '上海汇金奥特莱斯(南广场店)', '海之杰大酒店', '星巴克(上海南站店)', '上海南站治安派出所治安岗亭']"
5 |
--------------------------------------------------------------------------------
/坐标系转换/CoorChange.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | auther:chenxu
4 | content:火星、百度、高德、谷歌等坐标系之间的转换
5 | '''
6 | import json
7 | import math
8 |
9 |
10 | x_pi = 3.14159265358979324 * 3000.0 / 180.0
11 | pi = 3.1415926535897932384626 # π
12 | a = 6378245.0 # 长半轴
13 | ee = 0.00669342162296594323 # 扁率
14 |
15 |
16 |
17 |
18 | def gcj02tobd09(lng, lat):
19 | """
20 |
21 | 火星坐标系(GCJ-02)转百度坐标系(BD-09)
22 |
23 | 谷歌、高德——>百度
24 |
25 | :param lng:火星坐标经度
26 |
27 | :param lat:火星坐标纬度
28 |
29 | :return:
30 |
31 | """
32 |
33 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi)
34 |
35 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi)
36 |
37 | bd_lng = z * math.cos(theta) + 0.0065
38 |
39 | bd_lat = z * math.sin(theta) + 0.006
40 |
41 | return [bd_lng, bd_lat]
42 |
43 |
44 | def bd09togcj02(bd_lon, bd_lat):
45 | """
46 |
47 | 百度坐标系(BD-09)转火星坐标系(GCJ-02)
48 |
49 | 百度——>谷歌、高德
50 |
51 | :param bd_lat:百度坐标纬度
52 |
53 | :param bd_lon:百度坐标经度
54 |
55 | :return:转换后的坐标列表形式
56 |
57 | """
58 |
59 | x = bd_lon - 0.0065
60 |
61 | y = bd_lat - 0.006
62 |
63 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi)
64 |
65 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi)
66 |
67 | gg_lng = z * math.cos(theta)
68 |
69 | gg_lat = z * math.sin(theta)
70 |
71 | return [gg_lng, gg_lat]
72 |
73 |
74 | def wgs84togcj02(lng, lat):
75 | """
76 |
77 | WGS84转GCJ02(火星坐标系)
78 |
79 | :param lng:WGS84坐标系的经度
80 |
81 | :param lat:WGS84坐标系的纬度
82 |
83 | :return:
84 |
85 | """
86 |
87 | if out_of_china(lng, lat): # 判断是否在国内
88 |
89 | return lng, lat
90 |
91 | dlat = transformlat(lng - 105.0, lat - 35.0)
92 |
93 | dlng = transformlng(lng - 105.0, lat - 35.0)
94 |
95 | radlat = lat / 180.0 * pi
96 |
97 | magic = math.sin(radlat)
98 |
99 | magic = 1 - ee * magic * magic
100 |
101 | sqrtmagic = math.sqrt(magic)
102 |
103 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)
104 |
105 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)
106 |
107 | mglat = lat + dlat
108 |
109 | mglng = lng + dlng
110 |
111 | return [mglng, mglat]
112 |
113 |
114 | def gcj02towgs84(lng, lat):
115 | """
116 |
117 | GCJ02(火星坐标系)转GPS84
118 |
119 | :param lng:火星坐标系的经度
120 |
121 | :param lat:火星坐标系纬度
122 |
123 | :return:
124 |
125 | """
126 |
127 | if out_of_china(lng, lat):
128 | return lng, lat
129 |
130 | dlat = transformlat(lng - 105.0, lat - 35.0)
131 |
132 | dlng = transformlng(lng - 105.0, lat - 35.0)
133 |
134 | radlat = lat / 180.0 * pi
135 |
136 | magic = math.sin(radlat)
137 |
138 | magic = 1 - ee * magic * magic
139 |
140 | sqrtmagic = math.sqrt(magic)
141 |
142 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)
143 |
144 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)
145 |
146 | mglat = lat + dlat
147 |
148 | mglng = lng + dlng
149 |
150 | return [lng * 2 - mglng, lat * 2 - mglat]
151 |
152 |
153 | def transformlat(lng, lat):
154 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng))
155 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 *math.sin(2.0 * lng * pi)) * 2.0 / 3.0
156 | ret += (20.0 * math.sin(lat * pi) + 40.0 *math.sin(lat / 3.0 * pi)) * 2.0 / 3.0
157 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * math.sin(lat * pi / 30.0)) * 2.0 / 3.0
158 | return ret
159 |
160 |
161 | def transformlng(lng, lat):
162 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng))
163 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * math.sin(2.0 * lng * pi)) * 2.0 / 3.0
164 | ret += (20.0 * math.sin(lng * pi) + 40.0 * math.sin(lng / 3.0 * pi)) * 2.0 / 3.0
165 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * math.sin(lng / 30.0 * pi)) * 2.0 / 3.0
166 | return ret
167 |
168 |
169 | def out_of_china(lng, lat):
170 | """
171 |
172 | 判断是否在国内,不在国内不做偏移
173 |
174 | :param lng:
175 |
176 | :param lat:
177 |
178 | :return:
179 |
180 | """
181 |
182 | if lng < 72.004 or lng > 137.8347:
183 | return True
184 |
185 | if lat < 0.8293 or lat > 55.8271:
186 | return True
187 |
188 | return False
189 |
190 |
191 | if __name__ == '__main__':
192 | lng = 121.475363
193 | lat = 31.228461
194 | result1 = gcj02tobd09(lng, lat)
195 | result2 = bd09togcj02(lng, lat)
196 | result3 = wgs84togcj02(lng, lat)
197 | result4 = gcj02towgs84(lng, lat)
198 | print(result4)
199 |
--------------------------------------------------------------------------------
/车辆图片识别车型/result.txt:
--------------------------------------------------------------------------------
1 | 颜色: 红色
2 | 车型预测
3 | 宝马3系 相似度: 0.9995583295822144
4 | 宝马5系 相似度: 1.8439248378854245e-05
5 | 宝马1系 相似度: 1.840721961343661e-05
6 | 宝马4系 相似度: 1.5401048585772514e-05
7 | 奔驰c级 相似度: 8.161055120581295e-06
8 |
--------------------------------------------------------------------------------
/车辆图片识别车型/vehicle_model.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import base64
3 | import matplotlib.pyplot as plt
4 | import matplotlib.image as mpimg
5 |
6 | # 输入你的api_key和secret_key,获取地址https://console.bce.baidu.com/ai
7 | api_key = '你的api_key'
8 | secret_key = '你的secret_key'
9 | url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + str(api_key) + '&client_secret=' + str(secret_key)
10 | res = requests.get(url).text
11 | a = eval(res)
12 | access_token = a['access_token']
13 | animal = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car?access_token=' + str(access_token)
14 | header = {
15 | 'Content-Type':'application/x-www-form-urlencoded'
16 | }
17 | data = {}
18 | with open('图片地址.jpg', 'rb') as f:
19 | image = base64.b64encode(f.read())
20 | data["image"] = str(image, 'utf-8')
21 | res2 = requests.post(url=animal,data=data, headers=header).text
22 | print('颜色:',eval(res2)['color_result'])
23 | print('车型预测')
24 | for each in eval(res2)['result']:
25 | print(each['name'], '\t相似度:', each['score'])
26 | plt.imshow(mpimg.imread(f))
27 | plt.show()
28 |
--------------------------------------------------------------------------------
/车辆图片识别车型/样本车辆.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hi-weijun/Useful-Python-Script/2868a2ad20b9b123034e406f373d23a0dde4f0d0/车辆图片识别车型/样本车辆.jpg
--------------------------------------------------------------------------------