1.计算图片逆光度

from matplotlib import pyplot as plt
import cv2
import numpy as np
import os
import mathdef get_fm(file_name):image = cv2.imread(file_name,0)hist = cv2.calcHist([image],[0],None,[256],[0,256])nums=image.shape[0]*image.shape[1]hist=hist/nums# 总体均值u=0for i in range(256):u+=hist[i]*i# print(u)# 总体方差a=0for i in range(256):a+=hist[i]*pow((i-u),2)# print(a)# 逆光度dbl=np.sqrt(a)return dbl# file_name='data2/img/blur (8).jpg'
# dbl=get_fm(file_name)
# print(dbl)path='img/'
for file in os.listdir(path):file_name=path+filedbl=get_fm(file_name)print(file, dbl)

2.图像傅里叶变换

# -*- coding: utf-8 -*-
import cv2
import numpy as np
from matplotlib import pyplot as plt#读取图像
file_name="img/a.jpg"
img = cv2.imread(file_name, 0)
img=cv2.resize(img,(500,500))#快速傅里叶变换算法得到频率分布
f = np.fft.fft2(img)
#默认结果中心点位置是在左上角,
#调用fftshift()函数转移到中间位置
fshift = np.fft.fftshift(f)
#fft结果是复数, 其绝对值结果是振幅
fimg = np.log(np.abs(fshift))# 1.高通滤波——把中心的低频信息都去掉,保留周围的高频信息
area=30
rows, cols = img.shape
crow, ccol = int(rows/2), int(cols/2)
fshift[crow-area:crow+area, ccol-area:ccol+area] = 0# # 2.低通滤波——保留中心的低频信息,把周围的高频信息都去掉
# area=30
# rows, cols = img.shape
# crow,ccol = int(rows/2), int(cols/2)
# mask = np.zeros((rows, cols), np.uint8)
# mask[crow-area:crow+area, ccol-area:ccol+area] = 1
# f = fshift * mask#傅里叶逆变换
ishift = np.fft.ifftshift(fshift)
iimg = np.fft.ifft2(ishift)
iimg = np.abs(iimg)# cv2.imwrite("data/data1/test/a1-sharp.jpg",iimg)# #展示结果
# plt.subplot(221), plt.imshow(img, 'gray'), plt.title('Original Fourier')
# plt.axis('off')
# plt.subplot(222), plt.imshow(fimg, 'gray'), plt.title('Fourier Fourier')
# plt.axis('off')
# plt.subplot(223), plt.imshow(iimg, 'gray'), plt.title('Fourier Fourier')
# plt.axis('off')
# plt.show()

3.寻找信号的波峰波谷

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal #滤波等# xxx = np.arange(0, 1000)
# yyy = np.sin(xxx*np.pi/180)# z1 = np.polyfit(xxx, yyy, 7) # 用7次多项式拟合
# p1 = np.poly1d(z1) #多项式系数
# yvals=p1(xxx) xxx = np.arange(0, 1000)
yvals = np.sin(xxx*np.pi/180)# 寻找极大值
maxs_x=signal.argrelextrema(yvals,np.greater)[0]
maxs_y=yvals[signal.argrelextrema(yvals, np.greater)]# 寻找极小值
mins_x=signal.argrelextrema(yvals,np.less)[0]
mins_y=yvals[signal.argrelextrema(yvals, np.less)]
print(mins_x, mins_y) #极大值的x轴plt.plot(xxx, yvals, 'r',label='polyfit values')
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.plot(maxs_x,maxs_y, 'o', color='blue', markersize=5) #极大值点
plt.plot(mins_x, mins_y,'o', color='green', markersize=5) #极小值点
plt.show()

4.计算人脸的俯仰值/侧脸值

import glob
from PIL import Image
import os
import numpy as np
import xlrd
import xlutils.copy
import dlib
import cv2
from PIL import Image
import numpy as np
import time
import imutilsdef face_detect(pic):detector = dlib.get_frontal_face_detector()predictor = dlib.shape_predictor('class/shape_predictor_68_face_landmarks.dat')img = np.copy(pic)# img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)# 人脸数rectspoints = []rects = detector(img, 1)if len(rects)!=1:print("face detection fail!")else:landmarks = np.matrix([[p.x, p.y] for p in predictor(img, rects[0]).parts()])for idx, point in enumerate(landmarks):x = point[0, 0]y = point[0, 1]points.append([x, y])# 画图和点cv2.circle(img, (x,y), 9, (0, 255, 0), thickness=-1, lineType=cv2.FILLED)cv2.putText(img, str(idx), (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 0, 255), 2,cv2.LINE_AA)return img, np.array(points)def get_radio(point):# 侧脸:24-12  18-24   (39-27  42-27)left = abs(point[39][0] - point[27][0])right = abs(point[42][0] - point[27][0])num1=max(left,right)num2=min(left,right)sideways_radio = num1/num2# 俯仰1:top:6-0(21-22)中间    median:26(30) 鼻尖    bottom:41(57)下嘴唇# 俯仰2:26-24/41-29   (30-27/57-33)top=np.sqrt( (point[30][0]-point[27][0])**2 + (point[30][1]-point[27][1])**2 )bottom=np.sqrt( (point[57][0]-point[33][0])**2 + (point[57][1]-point[33][1])**2 )pitch_radio=top/bottomtop2=point[30][1]-point[27][1]bottom2=point[57][1]-point[33][1]pitch_radio2=top2/bottom2# print(top,bottom,pitch_radio)return sideways_radio,pitch_radio,pitch_radio2f1 = open("img/data.txt", 'w+')
n=0
path = "img/0/"
# save="img4/src/1-2/"
for root,dirs,files in os.walk(path):for file in files:if file.endswith('jpg'):file_name=root+"/"+filen+=1# 人脸检测,获取坐标点pic=cv2.imread(file_name)img_face,point=face_detect(pic)   #人脸检测print(point)if len(point)!=0:sideways_radio,pitch_radio,pitch_radio2=get_radio(point)print(n,root+file,sideways_radio,pitch_radio)f1.write(str(n)+'  '+(root + file)+'  '+str(sideways_radio)+'  '+str(pitch_radio)+'  '+str(pitch_radio2)+"  \n")else:f1.write(str(n) + '  ' + (root + file) + '  ' + str(0) + '  ' + str(0)+ '  ' + str(0)+"  \n")

常用方法(图片逆光度、傅里叶变换、寻找波峰波谷、计算俯仰/侧脸)相关推荐

  1. PyQt5_寻找波峰波谷并可视化

    在K线图分析中经常需要查看波峰与波谷的情况,鉴别是否后续高点是否高于或低于前一个高点,后续低点是否高于或低于前一个低点:另一种情况是寻找曲线形态,诸如头肩顶(底).双重顶(底)等.在K线图中直接查找会 ...

  2. 基于matlab的简单的寻找波峰波谷处理方法

    [plain] view plain copy clc; close all; clear; % 节点信息 data=[105.03 99.18 84.965 72.445 68.994 77.265 ...

  3. Matlab找波峰波谷

    准备一组数据 链接如下: 链接:https://pan.baidu.com/s/1Da2GRYIhHVSaWvO7OxrQTw  提取码:bgji 在Mablab中输入以下代码做相应的清除工作 clc ...

  4. matlab如何寻找波谷,波峰波谷法计算信号的周期及其Matlab程序

    波峰波谷法原理是:查找信号相邻波峰波谷间隔采样点的数量,乘上采样间隔的时间,最后求平均值即是信号的周期.但该方法对噪声较为敏感,采用波峰波谷法计算滤波后信号的周期,如图所示. 该方法主要是需要找到信号 ...

  5. 第四课 FZHOP硬件版上位机教程-曲线图-波峰波谷取值(CP1H版)

    大家好,前面我们了解了FZHOP硬件版的动作步操作方法(不熟悉的同学可以先回去看看第三课),现在我们可以来继续我们的曲线图学习了 在工业应用控制中,我们经常需要对曲线的波峰或者波谷的峰值进行计算,用于 ...

  6. 信号波峰波谷二阶差分识别算法

    1.聊一聊 其实每个人在无助的时候都需要一句"Cry On My Shoulder!" 今天跟大家介绍一种波峰波谷的检测方法,不是很难,不过能够凸显数学在编程算法中的重要作用. 2 ...

  7. Faas 典型场景——应用负载有显著的波峰波谷,典型用例-基于事件的数据处理...

    Serverless适用的两大场景 场景一:应用负载有显著的波峰波谷 Serverless化与否的评判标准并不是公司规模的大小,而是其业务背后的具体技术问题,比如业务波峰波谷明显,如何实现削峰填谷.一 ...

  8. 图像投影特征图的波峰波谷查找的相关原理及利用差分遍历法查找波峰的OpenCV代码

    图像处理开发需求.图像处理接私活挣零花钱,请加微信/QQ 2487872782 图像处理开发资料.图像处理技术交流请加QQ群,群号 271891601 什么叫图像的投影特征图?定义如下: 图像水平方向 ...

  9. python波峰波谷算法_波动均分算法

    波动均分算法 by leeenx on 2018-01-11 「波动」和「均分」大部分读者朋友是知道的,但看到「波动均分」应该是一头雾水的.其实,这个名词是笔者拼凑出来的. 什么是「波动均分」? 把指 ...

最新文章

  1. 国内第1本jBPM专著即将隆重上市!
  2. Oracle之物化视图
  3. 寄存器和存储器的区别_寄存器、累加器、暂存器都是什么?它们有什么区别?...
  4. This graphics driver could not find compatible graphics hardware 解决
  5. MySQL数据库InnoDB存储引擎中的锁机制--转载
  6. python初学者用什么编辑器好_新人学 python 选什么编辑器比较好呢??
  7. linux下面实时查看进程,内存以及cpu使用情况使用命令
  8. mysql can't open file: '..frm'_mysqldump 导出数据时出现can’t opne file ‘xx.frm’ (errno:24)错误...
  9. JTS(Geometry)工具类
  10. 机器学习实战 Tricks
  11. linux 如何避免进程killed_Linux 内核 / 进程管理 / 如何描述一个进程?
  12. docker进阶与实战 3 理解docker镜像
  13. vs2010开发activex(MFC)控件/ie插件(一)
  14. Mybatis之分页插件PageHelper工作原理
  15. 如何选择和设置SEO关键词
  16. html自定义图例,自定义 highcharts 图例之 symbol
  17. 【原创】基于TensorFlow2识别人是否配戴眼镜的研究
  18. 世界上最难的视觉图_世界上最难攀登的十座高峰!让人步步惊心
  19. [算法导论] 最大差值、最小差值
  20. ChatGPT不到1分钟生成全部代码,你就说慌不慌吧?

热门文章

  1. EPI——部分笔记 + 资源无偿分享(百度网盘)~
  2. 打造室内 “店铺级” 定位的 Petal Maps Platform,正在重塑数字生活新范式
  3. Lua基础:Lua基础
  4. SAP License:ERP系统是什么意思
  5. 衡阳师范学院计算机考试题库,衡阳师范学院自主招生综合素质测试面试题方法指导...
  6. 学习用WinRAR解压缩软件解压下载的PPStream压缩包
  7. 《How powerful are graph neural networks》论文翻译
  8. 计算机中丢失ENWeb,vbaen32.olb
  9. 025-2018-1011 re模块
  10. 使用VS Code五年后,我决定换回Pycharm