其他分享
首页 > 其他分享> > 05_ROI区域

05_ROI区域

作者:互联网

# 1. 位置提取ROI

import cv2 #opencv的缩写为cv2
# import matplotlib.pyplot as plt # matplotlib库用于绘图展示
# import numpy as np   # numpy数值计算工具包
#
#
def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
#
img = cv2.imread('D:/pycharm/pycharm-cope/opencv/resource/photo/01_cat.jpg')
# cat = img[0:200,0:200] # 选择图片感兴趣的区域
# cv_show('cat',cat)
# # 2. 通道提取ROI
# #2.1 分离 BGR 通道
# img = cv2.imread('D:/pycharm/pycharm-cope/opencv/resource/photo/01_cat.jpg')
# b,g,r = cv2.split(img)
# # b.shape: (414, 500)
# # g.shape: (414, 500)
# # r.shape: (414, 500)
# # img.shape: (414, 500, 3)
# cv_show('cat_b',b)
# print('b.shape:',b.shape) # B通道,单通道,灰度图
# cv_show('cat_g',g)
# print('g.shape:',g.shape) # G通道,单通道,灰度图
# cv_show('cat_r',r)
# print('r.shape:',r.shape) # R通道,单通道,灰度图
# img = cv2.merge((b,g,r))
# cv_show('cat', img)
# print('img.shape:',img.shape) # 3 通道,彩色图
# ## 2.2 展示 R 通道
# # # 只保留 R
# img = cv2.imread('D:/pycharm/pycharm-cope/opencv/resource/photo/01_cat.jpg')
# b,g,r = cv2.split(img)
# img = cv2.merge((b,g,r))
# cur_img = img.copy()
# cur_img[:,:,0] = 0
# cur_img[:,:,1] = 0
# cv_show('R',cur_img)
# ## 2.3 展示 G 通道
# # 只保留 G
# img = cv2.imread('D:/pycharm/pycharm-cope/opencv/resource/photo/01_cat.jpg')
# cur_img = img.copy()
# cur_img[:,:,0] = 0
# cur_img[:,:,2] = 0
# cv_show('G',cur_img)
# # ## 2.4 展示 R 通道
# # 只保留 R
img = cv2.imread('D:/pycharm/pycharm-cope/opencv/resource/photo/01_cat.jpg')
cur_img = img.copy()
cur_img[:,:,1] = 0
cur_img[:,:,2] = 0
cv_show('B',cur_img)

 

标签:ROI,cur,img,05,cv2,cat,shape,区域,pycharm
来源: https://www.cnblogs.com/tuyin/p/16546175.html