---
# System prepended metadata

title: OpenCV 基礎篇-實作-惡搞我家小孩part1(美元鈔票)
tags: [OpenCV, 影像相加]

---

###### tags: `OpenCV`,`影像相加`
# OpenCV 基礎篇-實作-惡搞我家小孩part1(美元鈔票)

```python=
#因為要放在美鈔人頭上,顏色需先淡化,照片角度也要挑一下,不然會很奇怪
#使用cv2.add調整顏色
import cv2
import numpy as np
#惡搞自家女兒照
newnew=cv2.imread("new33.jpg",0)  #newnew是我女兒的小名
print(newnew.shape) #(600, 450)
img1=np.ones((600,450),dtype=np.uint8)*55 #調整適合的灰階程度
img3=cv2.add(img1,newnew)
r=cv2.imwrite("newOK.bmp",img3) #儲存影像
cv2.imshow("newnew",newnew)
cv2.imshow("add",img3)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
![](https://i.imgur.com/UFhyWYg.png)

```python=
#進行臉部大小的裁切與轉移
import cv2
newnew=cv2.imread("newOK.bmp",0) #把剛剛調整儲存的影像讀進來
dollar=cv2.imread("dollar.bmp",cv2.IMREAD_UNCHANGED)
cv2.imshow("newnew",newnew)
cv2.imshow("dollar",dollar)
face=newnew[165:295,180:280]#長:130,寬:100
dollar[210:340,210:310]=face 
#newnew的頭像矩陣貼到美元影像,長寬都要一致
cv2.imshow("result",dollar)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
![](https://i.imgur.com/jLIU5tj.png)



