擅长:python、mysql、java
<p>因为你需要人脸识别,所以只需要人脸细节,而不需要周围环境。周围的物体由于误报而降低了精确度。
您可以按照以下步骤增强图像质量:</p>
<p>步骤1:仅使用haarcascade检测人脸</p>
<pre><code>face_cascade = cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml’)
faces_detected = face_cascade.detectMultiScale(img, scaleFactor=1.1, minNeighbors=5)
(x, y, w, h) = faces_detected[0]
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 1);
cv2.imshow(img)
</code></pre>
<p>步骤2:裁剪图像</p>
<pre><code>p = 20 #padding
img_cropped = img[y-p+1:y+h+p, x-p+1:x+w+p]
</code></pre>
<p>步骤3:重塑为原始尺寸</p>
<pre><code>im_reshape = cv2.resize(img_cropped , (img.shape[0], img.shape[1]), interpolation=cv2.INTER_LINEAR)
</code></pre>
<p>步骤3:标准化图像以固定亮度</p>
<pre><code>norm_img = np.zeros((img.shape[0], img.shape[1]))
norm_img = cv2.normalize(img, norm_img, 0, 255, cv2.NORM_MINMAX)
</code></pre>
<p>第三步:<code>norm_img</code>到<code>caffemodel</code></p>
<p>这种方法可以显著提高精度</p>