(一)opencv_py之roi区域
opencv_py之roi区域
参考:
1. roi
Sometimes, you will have to play with certain region of images. For eye detection in images, first face detection is done all over the image. When a face is obtained, we select the face region alone and search for eyes inside it instead of searching the whole image. It improves accuracy (because eyes are always on faces 😄 ) and performance (because we search in a small area).
2. 示例
import numpy as np
import cv2 as cv
def showImage(img):
cv.namedWindow("image")
cv.imshow("image", img)
cv.waitKey()
cv.destroyAllWindows()
def printImageInfo(img):
width=img.shape[0]
height=img.shape[1]
print("width is", width)
print("height is", height)
# 读取图片
imgLena=cv.imread("../lena.jpg")
#showImage(imgLena)
printImageInfo(imgLena)
# roi, 这里是切片,指向同一底层的数组
imgFace=imgLena[100:200, 100:200]
showImage(imgFace)
printImageInfo(imgFace)
# 修改roi, 原始图片也被修改
# for row in range(0,100):
# for colomn in range(0,100):
# for channel in range(0,3):
# imgFace[row][colomn][channel]=255
#
# showImage(imgLena)
imgPeople=cv.imread("../image/people.jpg")
#showImage(imgPeople)
printImageInfo(imgPeople)
imgFace2=imgPeople[100:200, 100:200]
showImage(imgFace2)
# g(x)=(1−α)f0(x)+αf1(x)
# By varying α from 0→1, you can perform a cool transition between one image to another.
# cv.addWeighted() applies following equation on the image.
# dst=α⋅img1+β⋅img2+γ
imgBlend=cv.addWeighted(imgFace, 0.7, imgFace2, 0.3, 0)
showImage(imgBlend)