Skip to content

Commit

Permalink
Merge pull request vipstone#16 from archersmind/add_en_doc
Browse files Browse the repository at this point in the history
Doc: Initial commit for English Documentation
  • Loading branch information
vipstone authored Jul 2, 2018
2 parents b513339 + a2d0e05 commit 978155c
Show file tree
Hide file tree
Showing 22 changed files with 1,561 additions and 16 deletions.
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[English Doc](README_en.md)
# 功能 #

1. 人脸检测、识别(图片、视频)
1. 轮廓标识
1. 头像合成(给人戴帽子)
1. 数字化妆(画口红、眉毛、眼睛等)
1. 性别识别
1. 表情识别(生气、厌恶、恐惧、开心、难过、惊喜、平静等七种情绪)
2. 视频对象提取
3. 图片修复(可用于水印去除)
4. 图片自动上色
3. 眼动追踪(待完善)
3. 换脸(待完善)
2. 轮廓标识
3. 头像合成(给人戴帽子)
4. 数字化妆(画口红、眉毛、眼睛等)
5. 性别识别
6. 表情识别(生气、厌恶、恐惧、开心、难过、惊喜、平静等七种情绪)
7. 视频对象提取
8. 图片修复(可用于水印去除)
9. 图片自动上色
10. 眼动追踪(待完善)
11. 换脸(待完善)

**查看功能预览↓↓↓**

Expand Down Expand Up @@ -161,10 +162,8 @@ Dlib模型训练方法

Tesseract模型训练方法



# 贡献者名单(特别感谢)

[archersmind](https://github.com/archersmind)

# 贡献者名单(特别感谢)

[archersmind](https://github.com/archersmind)

[rishab-sharma](https://github.com/rishab-sharma)
168 changes: 168 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
Translation for English Documentations are Working In Progress

# Functions #

1. Face Detection and Recognition(From Image or Video)
2. Facial Landmark
3. Image compositing(e.g. Wear Hat For a Figure)
4. Face Makeup(e.g. Lipstick, Eyebrow, Eyes, etc)
5. Gender Recognition
6. Emotion Recognition(e.g. Angry, Disgust, Fear, Happy, Sad, Surprise, Neutral)
7. Video Object Extraction
8. Image Denoising(e.g. Watermark Removal)
9. Image Colorization
10. Eye Tracking(W.I.P)
11. Face Replacement(W.I.P)

# Development Environment #

- Windows 10(x64)
- Python 3.6.4
- OpenCV 3.4.1
- Dlib 19.8.1
- face_recognition 1.2.2
- keras 2.1.6
- tensorflow 1.8.0
- Tesseract OCR 4.0.0-beta.1


# Tutorials #

[OpenCV Setup](doc-en/settingup.md)

[Tesseract OCR Text Recognition](doc-en/tesseractOCR.md)

[Face Detection From Image(OpenCV based)](doc-en/detectionOpenCV.md)

[Face Detection From Image(Dlib based)](doc-en/detectionDlib.md)

[Face Detection From Video(OpenCV based)](doc-en/videoOpenCV.md)

[Face Detection From Video(Dlib based)](doc-en/videoDlib.md)

[Face Outline Recognition](doc-en/faceRecognitionOutline.md)

[Face Makeup](doc-en/faceRecognitionMakeup.md)

[Face Recognition From Video](doc-en/faceRecognition.md)

[Image Compositing](doc-en/compose.md)

[Gender Recognition](doc-en/gender.md)

[Emotion Recognition](doc-en/emotion.md)

[Video Object Extraction](doc-en/hsv-opencv.md)

[Image Denoising](doc-en/inpaint.md)


# Other Related Tutorials #

[Ubuntu Software And pip Sources Update](doc-en/ubuntuChange.md)

[pip/pip3 Update To Repository Inside China Mainland——Windows](doc-en/pipChange.md)

[Chinese Font Support In OpenCV](doc-en/chinese.md)

[Mouse Drawing——Based on OpenCV](doc-en/opencv/mouse.md)


# Preview #

**Face Outline Recognition**

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/face_recognition-outline.png" width = "250" height = "300" alt="绘制脸部轮廓" />

----------

**68-point Facial Landmark Detection**

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/dlib68.png" width = "230" height = "300" alt="人脸68个关键点标识" />

----------

**Image Compositing**

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/compose.png" width = "200" height = "300" alt="头像特效合成" />

----------

**Gender Recognition**

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/gender.png" width = "430" height = "220" alt="性别识别" />

----------

**Emotion Recognition**

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/emotion.png" width = "250" height = "300" alt="表情识别" />

----------

**Face Makeup**

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/faceRecognitionMakeup-1.png" width = "450" height = "300" alt="视频人脸识别" />

----------

**Face Detection From Video**

![](https://raw.githubusercontent.com/vipstone/faceai/master/res/video-jiance.gif)

----------

**Face Recognition From Video**

![](https://raw.githubusercontent.com/vipstone/faceai/master/res/faceRecognition.gif)

----------

**Face Recognition From Video**

![](http://icdn.apigo.cn/opencv-hsv.gif)

----------

**Image Denoising**

![](http://icdn.apigo.cn/inpaint.png?2)

----------

**Image Colorization**

![](http://icdn.apigo.cn/colorize-faceai.png)

----------

# Background #

Requirements

Face Recognition :OpenCV / Dlib / face_recognition

Gender Recognition:keras + tensorflow

Text Recognition:Tesseract OCR


### TODO ###

Face Replacement——W.I.P

Eye Tracking——W.I.P

Dlib Performance Optimization

Dlib Model Training

Tesseract Model Training



# Contributor

[archersmind](https://github.com/archersmind)

[rishab-sharma](https://github.com/rishab-sharma)
70 changes: 70 additions & 0 deletions doc-en/chinese.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# OpenCV添加中文 #
OpenCV添加文字的方法putText(...),添加英文是没有问题的,但如果你要添加中文就会出现“???”的乱码,需要特殊处理一下。

下文提供封装好的(代码)方法,供OpenCV添加中文使用。

# 效果预览 #

<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/chinese.png" width = "300" height = "200" alt="效果展示" />

# 实现思路 #
使用PIL的图片绘制添加中文,可以指定字体文件,那么也就是说使用PIL可以实现中文的输出。

有思路之后,接下来的工作就简单了。

1. OpenCV图片格式转换成PIL的图片格式;
1. 使用PIL绘制文字;
1. PIL图片格式转换成OpenCV的图片格式;

# 代码分解 #

**OpenCV图片转换为PIL图片格式**

```
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
```

**使用PIL绘制文字**
```
draw = ImageDraw.Draw(img)
fontText = ImageFont.truetype("font/simsun.ttc", textSize, encoding="utf-8")
draw.text((left, top), "文字内容", textColor, font=fontText)
```
字体文件为:simsun.ttc,Windows可以在C:\Windows\Fonts下面查找。



**PIL图片格式转换成OpenCV的图片格式**
```
cv2.cvtColor(numpy.asarray(img), cv2.COLOR_RGB2BGR)
```


# 完整代码 #

封装好的完整方法

```
#coding=utf-8
#中文乱码处理
import cv2
import numpy
from PIL import Image, ImageDraw, ImageFont
def cv2ImgAddText(img, text, left, top, textColor=(0, 255, 0), textSize=20):
if (isinstance(img, numpy.ndarray)): #判断是否OpenCV图片类型
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img)
fontText = ImageFont.truetype(
"font/simsun.ttc", textSize, encoding="utf-8")
draw.text((left, top), text, textColor, font=fontText)
return cv2.cvtColor(numpy.asarray(img), cv2.COLOR_RGB2BGR)
```

代码调用

```
img = cv2ImgAddText(img, "大家好,我是星爷", 140, 60, (255, 255, 0), 20)
```
6 changes: 6 additions & 0 deletions doc-en/colorize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 图片上色 #


安装scikit-image模块:scikit-image (a.k.a. skimage) 是一个图像处理和计算机视觉的算法集合。
>sudo pip3 install scikit-image
66 changes: 66 additions & 0 deletions doc-en/compose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 头像特效合成

实现思路:使用OpenCV检测出头部位置,向上移动20像素添加虚拟帽子,帽子的宽度等于脸的大小,高度等比缩小,需要注意的是如果高度小于脸部向上移动20像素的值,那么帽子的高度就等于最小高度=(脸部位置-20)。
为什么是20而不是30或者40,因为取得是检测的脸部和头顶的一般距离20,开发者可自己调整。


**注意事项**

图片合成元件,要是黑背景图片,透明的图片也会有问题,在ps手动处理一下透明图片,添加新图层,选中alt+Del添加黑背景,把新图层层级放到最底部即可。

# 效果图预览 #
<img src="https://raw.githubusercontent.com/vipstone/faceai/master/res/compose.png" width = "200" height = "300" alt="头像特效合成" />


## 代码实现 ##
```
#coding=utf-8
import cv2
# OpenCV人脸识别分类器
classifier = cv2.CascadeClassifier(
"C:\Python36\Lib\site-packages\opencv-master\data\haarcascades\haarcascade_frontalface_default.xml"
)
img = cv2.imread("img/ag-3.png") # 读取图片
imgCompose = cv2.imread("img/compose/maozi-1.png")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 转换灰色
color = (0, 255, 0) # 定义绘制颜色
# 调用识别人脸
faceRects = classifier.detectMultiScale(
gray, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32))
if len(faceRects): # 大于0则检测到人脸
for faceRect in faceRects:
x, y, w, h = faceRect
sp = imgCompose.shape
imgComposeSizeH = int(sp[0]/sp[1]*w)
if imgComposeSizeH>(y-20):
imgComposeSizeH=(y-20)
imgComposeSize = cv2.resize(imgCompose,(w, imgComposeSizeH), interpolation=cv2.INTER_NEAREST)
top = (y-imgComposeSizeH-20)
if top<=0:
top=0
rows, cols, channels = imgComposeSize.shape
roi = img[top:top+rows,x:x+cols]
# Now create a mask of logo and create its inverse mask also
img2gray = cv2.cvtColor(imgComposeSize, cv2.COLOR_RGB2GRAY)
ret, mask = cv2.threshold(img2gray, 10, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
# Now black-out the area of logo in ROI
img1_bg = cv2.bitwise_and(roi, roi, mask=mask_inv)
# Take only region of logo from logo image.
img2_fg = cv2.bitwise_and(imgComposeSize, imgComposeSize, mask=mask)
# Put logo in ROI and modify the main image
dst = cv2.add(img1_bg, img2_fg)
img[top:top+rows, x:x+cols] = dst
cv2.imshow("image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```

Loading

0 comments on commit 978155c

Please sign in to comment.