项目实训记录

这段时间我进行的工作有:OpenCV有关算法的学习,写识别关键点的代码。
学习有关算法主要是在网络上进行,下面是其中几个比较有用的网址:
https://blog.csdn.net/playezio/article/details/80471000
https://www.cnblogs.com/aby321/p/11025129.html
https://zhuanlan.zhihu.com/p/259919869
具体算法十分复杂,需要用到许多公式和数学知识,这里不再一一详述,这里想说一下算法中很重要的一点是harr特征,是用于物体识别的一种数字图像特征,因为与哈尔小波转换相似而得名。haar特征反应的是图像的灰度变化,haar特征用黑白两种矩形框表示特征,在特征模板内,用白色矩形块的像素减去黑色矩形块的像素的差值和来表示模块的特征。哈尔特征广义分为三类:边缘特征,线性特征,中心特征。
在这里插入图片描述
我以前学习深度学习有关特征的知识时很少听说这个,但是在人眼识别算法中这是很有用的一个特征。
此外,学习算法时比较有意思的一点是,很多有关教程都讲到了ADABOOST算法,这是机器学习领域里很著名的一个算法,当时学习机器学习这门课程时也是重难点之一,但是我们一开始完全没有想到用这个来实现,这说明我们学习了课程之后还要学会怎么应用,许多高精尖技术其实都是由基础的算法实现的,不能忽视基础知识。
下面是目前写出的代码中的重要部分,完整代码会放在项目的GitHub里面。

def eye_aspect_ratio(eye):
	# compute the euclidean distances between the two sets of
	# vertical eye landmarks (x, y)-coordinates
	A = dist.euclidean(eye[1], eye[5])
	B = dist.euclidean(eye[2], eye[4])
	# compute the euclidean distance between the horizontal
	# eye landmark (x, y)-coordinates
	C = dist.euclidean(eye[0], eye[3])
	# compute the eye aspect ratio
	ear = (A + B) / (2.0 * C)
	# return the eye aspect ratio
	return ear

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
# ap.add_argument("-p", "--shape-predictor", required=True,
# 	help="path to facial landmark predictor")
ap.add_argument("-v", "--video", type=str, default="",
	help="path to input video file")
args = vars(ap.parse_args())

# define two constants, one for the eye aspect ratio to indicate
# blink and then a second constant for the number of consecutive
# frames the eye must be below the threshold
EYE_AR_THRESH = 0.3
EYE_AR_CONSEC_FRAMES = 3
# initialize the frame counters and the total number of blinks
COUNTER = 0
TOTAL = 0

# initialize dlib's face detector (HOG-based) and then create
# the facial landmark predictor
print("[INFO] loading facial landmark predictor...")
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

# grab the indexes of the facial landmarks for the left and
# right eye, respectively
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]

# start the video stream thread
print("[INFO] starting video stream thread...")
vs = FileVideoStream(args["video"]).start()
fileStream = True
vs = VideoStream(src=0).start()
# vs = VideoStream(usePiCamera=True).start()
fileStream = False
time.sleep(1.0)

# loop over frames from the video stream
while True:
	# if this is a file video stream, then we need to check if
	# there any more frames left in the buffer to process
	if fileStream and not vs.more():
		break
	# grab the frame from the threaded video file stream, resize
	# it, and convert it to grayscale
	# channels)
	frame = vs.read()
	frame = imutils.resize(frame, width=450)
	gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
	# detect faces in the grayscale frame
	rects = detector(gray, 0)

但是目前的代码还存在问题,运行时总是报很多神奇的看不懂的错误,有时候还会闪退,接下来还需要继续修改.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值