python学习杂记

1#读取灰度图像
org_img = cv2.imread(‘img_bin.jpg’,0)

2#显示图像
import cv2

img = cv2.imread(‘Rachel.jpg’, 0)#直接读为灰度图像
cv2.imshow(‘WindowOne’, img)

3#plt 同时显示多幅图像
import matplotlib.pyplot as plt

plt.figure()
plt.subplot(1,2,1)
plt.imshow(images[i])
plt.subplot(1,2,2)
plt.imshow(maskes[i])
plt.show()

cv2.imread():读入图片,共两个参数,
第一个参数为要读入的图片文件名,
第二个参数为如何读取图片,
包括
cv2.IMREAD_COLOR:读入一副彩色图片;
cv2.IMREAD_GRAYSCALE:以灰度模式读入图片;
cv2.IMREAD_UNCHANGED:读入一幅图片,并包括其alpha通道。

4 #opencvAPI
https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#cv2.imread
imread
Loads an image from a file.

C++: Mat imread(const string& filename, int flags=1 )
Python: cv2.imread(filename[, flags]) → retval
C: IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
C: CvMat* cvLoadImageM(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
Python: cv.LoadImage(filename, iscolor=CV_LOAD_IMAGE_COLOR) → None
Python: cv.LoadImageM(filename, iscolor=CV_LOAD_IMAGE_COLOR) → None
Parameters:
filename – Name of file to be loaded.
flags –
Flags specifying the color type of a loaded image:

CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one

0 Return a 3-channel color image.
Note In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
=0 Return a grayscale image.
<0 Return the loaded image as is (with alpha channel).


距离变换-distanceTransform
1:Opencv中distanceTransform方法用于计算图像中每一个非零点距离离自己最近的零点的距离,distanceTransform的第二个Mat矩阵参数dst保存了每一个点与最近的零点的距离信息,图像上越亮的点,代表了离零点的距离越远。

原文:https://blog.csdn.net/z827997640/article/details/80461240

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值