# 常用镜头焦段统计（Python实现）

2 篇文章 0 订阅
2 篇文章 0 订阅

## 镜头焦段统计

### 2.思路

import exifread
import os
import seaborn as sns
import matplotlib.pyplot as plt


tags = exifread.process_file()


dic = {}
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
fname = os.path.join(root, name)
if '.jpg' not in fname.lower():
continue
with open(fname, "rb") as file:
if 'EXIF FocalLength' in tags.keys():
FocalLength = int(str(tags['EXIF FocalLength']))
else:
continue
if FocalLength in dic.keys():
dic[FocalLength] += 1
else:
dic[FocalLength] = 1


dic = dict(sorted(dic.items(), key=lambda x:x[0]))
top10 = list(dict(sorted(dic.items(), key=lambda x:x[1], reverse=True)).keys())[:11]
top10 = list(set(top10)|{24, 28, 35, 50, 85, 105, 200, 300, 400, 600})
# 这里展示的刻度是最多的十个和几个常用焦距（24 28 35 50 85等）的并集
sns.set()
plt.plot(dic.keys(), dic.values(), color='r')
plt.xticks(top10)
plt.xlabel("FocalLength")
plt.ylabel("Times")
plt.title("FocalLength Frenquency Since 2022.12.01")
plt.legend()
plt.show()
print(dic)


### 4.完整代码

import exifread
import os
import seaborn as sns
import matplotlib.pyplot as plt

dic = {}
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
fname = os.path.join(root, name)
if '.jpg' not in fname.lower():
continue
with open(fname, "rb") as file:
if 'EXIF FocalLength' in tags.keys():
FocalLength = int(str(tags['EXIF FocalLength']))
# print(FocalLength)
else:
continue
if FocalLength in dic.keys():
dic[FocalLength] += 1
else:
dic[FocalLength] = 1

dic = dict(sorted(dic.items(), key=lambda x:x[0]))
top10 = list(dict(sorted(dic.items(), key=lambda x:x[1], reverse=True)).keys())[:11]
top10 = list(set(top10)|{24, 28, 35, 50, 85, 105, 200, 300, 400, 600})
sns.set()
plt.plot(dic.keys(), dic.values(), color='r')
plt.xticks(top10)
plt.xlabel("FocalLength")
plt.ylabel("Times")
plt.title("FocalLength Frenquency Since 2022.12.01")
plt.legend()
plt.show()
print(dic)


• 4
点赞
• 5
收藏
觉得还不错? 一键收藏
• 1
评论
04-26 6287
09-22
10-14
09-21
01-09 1165
10-14 908
07-24
09-18
05-22 8万+
06-14 193
10-01 703
05-20 720
10-29

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。