opencv(一) python opencv 读写图片

1、读取并显示

1.1、代码

import cv2 as cv
img = cv.imread("dota.jpg")
cv.imshow("image_show",img)
cv.waitKey(0)
cv.destroyAllWindows()

1.2、函数解析

 (1)imread

 imread(filename[, flags]) -> retval

 

@param filename Name of file to be loaded.                              filename:欲显示图片的路径名字
 @param flags Flag that can take values of cv::ImreadMode      flags     :可选,以何种方式打开

总结:该函数的功能是找到相应的图片,然后转换为计算机能处理的格式(Mat),并返回。

 

The function imread loads an image from the specified file and returns it. If the image cannot be
   read (because of missing file, improper permissions, unsupported or invalid format), the function
  returns an empty matrix ( Mat::data==NULL ).

打开一张图片并返回,若图片不能读,返回null。

(2)imshow

 imshow(winname, mat) -> None
   @param winname Name of the window.   winname:显示图片 框 的名字
   @param mat Image to be shown.            mat: 将要显示的图片   

    总结:imshow的功能是告诉电脑,在哪里(winname)显示什么(Mat)

(3) waitKey()

           waitKey([, delay]) -> retval

 @param delay Delay in milliseconds. 0 is the special value that means "forever".

  若参数不为n(n≠0),则阻塞在这里n毫秒,为零,则一直阻塞有按键触发才终止。

(4)destroyAllWindows()     

destroyAllWindows() -> None

销毁所有由该程序创建的窗口。

2、读取并重写

           

import cv2 as cv
src = cv.imread("dota.jpg")
cv.imshow("image_orgine",src)
cv.imwrite("write_pic.png",src)
dst = cv.imread("write_pic.png")
cv.imshow("imgage_writed",dst)
cv.waitKey(0)
cv.destroyAllWindows()

2.1 imwrite

 imwrite(filename, img[, params]) -> retval
 @param filename Name of the file.            将要写入文件的名字(目标文件的名字)
 @param img Image to be saved.                源文件的名字   
 @param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags                     编码方式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值