Personal pycharm + opencv study notes, the actual case
Common code interpreter opencv
Based pycharm explain the development environment, anaconda of opencv module, the actual program case
The overall effect of the code
The transfer of local pictures, and displayed in the window
import cv2 as cv
src = cv.imread('kkk.jpg')
cv.namedWindow('input_image',cv.WINDOW_AUTOSIZE)
cv.imshow('input_image',src)
cv.waitKey(0)
cv.destroyAllWindows()
Code renderings
on the left is the project directory, the picture is stored in the project directory. If there is no storage, you need to call the picture of absolute addresses.
Code of fundamental
In the python with the import or to import from ... import corresponding module. Module is actually a collection of some of the functions and classes of files, it can achieve some of the appropriate function when we need to use these features directly to the appropriate module into our program, we can use. include the header file that is similar to the C language.
import cv2 as cv
#导入模块cv2,并定义别名cv
prompt
import, import as, form import and other statements simply import the modules and packages
module ( Module ) is a Python script file that can be imported
package ( Package Penalty for ) in order to avoid module name collisions, Python and the introduction of the method according to the directory to organize modules .
Subject code
1. Read the picture
src = cv.imread('kkk.jpg')
#cv2.imread(filepath,flags)读入一副图片
# filepath:要读入图片的完整路径
# flags:读入图片的标志
# cv2.IMREAD_COLOR:默认参数,读入一副彩色图片,忽略alpha通道
# cv2.IMREAD_GRAYSCALE:读入灰度图片
# cv2.IMREAD_UNCHANGED:顾名思义,读入完整图片,包括alpha通道
2. Create window
cv.namedWindow('input_image',cv.WINDOW_AUTOSIZE)
#cv2.namedWindow('winname',WINDOW_AUTOSIZE)新建一个显示窗口。可以指定窗口的类型
# winname:新建的窗口的名称,自取。
# WINDOW_AUTOSIZE:窗口的标识,一般默认为WINDOW_AUTOSIZE 。
# WINDOW_AUTOSIZE 窗口大小自动适应图片大小,并且不可手动更改。
# WINDOW_NORMAL 用户可以改变这个窗口大小
# WINDOW_OPENGL 窗口创建的时候会支持OpenGL
3. Display Pictures
cv.imshow('input_image',src)
# cv2.imshow('wname',img)显示图像,
# wname:显示图像的窗口的名字
# img:显示的图像(imread读入的图像),窗口大小自动调整为图片大小。
4. retaining windows
cv.waitKey(0)
#cv2.waitKey(ms)等待键盘输入,即等待指定的毫秒数看是否有键盘输入。
# 若在等待时间内按下任意键则返回按键的ASCII码,程序继续运行。
# 若没有按下任何键,超时后返回-1。
# 参数为0表示无限等待。不调用waitKey的话,窗口会一闪而逝,看不到显示的图片。
5. Destruction window
cv.destroyAllWindows()
#cv2.destroyAllWindow()销毁所有窗口
#cv2.destroyWindow(wname)销毁指定窗口
Miscellany
I am now going graduation project, using a remote camera for face recognition, interested friends can exchange contact me QQ: [email protected]
involve aspects: pycharm anaconda python QT opencv MySQL WiFi camera face recognition depth learning algorithm