初学opencv/基本操作

#coding:utf-8
"""
基本操作
"""
import numpy as np
import cv2
import matplotlib.pyplot as plt

#导入彩色图片
img = cv2.imread('images/messi.jpg',cv2.IMREAD_COLOR)
if img is None:
    print('error')
else:
    print('ok')
print(type(img))
print(img.shape)
print(img.dtype)
#显示图片
#plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
#plt.show()

img2 = np.ones((512,512,3),np.uint8)*254
#img3 = np.zeros((512,512,3),np.uint8)
#plt.imshow(img2)
#在图上画线条,起始位置,终止位置,颜色,粗细
cv2.line(img2,(0,0),(511,511),(128,314,50),5)
cv2.rectangle(img2,(100,200),(400,400),(17,25,133),3)
cv2.circle(img2,(200,200),23,(230,120,25),3)
#cv2.ellipse画椭圆或者弧线中心点坐标,长轴,短轴,角度,开始角度,结束角度
cv2.ellipse(img2,(256,256),(100,50),-45,0,180,(25,129,120),-1)
pts = np.array([[10,20],[150,200],[300,150],[200,50]],np.int32)
pts = pts.reshape((-1,1,2))
#画任意形状的线isClosed=True
cv2.polylines(img2,[pts],True,(0,255,255),3)
#给图片添加文字LINE_AA change to CV_AA
font = cv2.FONT_HERSHEY_COMPLEX
cv2.putText(img2,'SZJ-JOJO',(40,500),font,3,(254,34,12),cv2.CV_AA)
#修改图片颜色
for i in range(5):
    for j in range(5):
        img[170+i,220+j] = (22,111,0)
#font1 = cv2.FONT_HERSHEY_PLAIN
#cv2.putText(img,'haha',(171,221),font1,1,(0,0,0),cv2.CV_AA)
#改变图中物体位置
ball = img[280:340,330:390]
img[273:333,100:160] = ball
img[270:330,5:65] = ball
img[270:330,160:220] = ball

plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
#plt.imshow(img2)
plt.show()

结果

这里写图片描述

这里写图片描述

由于文件大小超过csdn限制的60M,所以分割成2个文件了,请注意下载。 Delphi-OpenCV (master) OpenCV version - 2.4.8 Development environment - Delphi XE2-XE5 Contributors: Laentir Valetov email: laex@bk.ru Mikhail Grigorev email: sleuthhound@gmail.com How to install: 1.Download the archive Delphi-OpenCV-master.zip 2.Unzip it to a convenient directory, thus get the following directory structure <Directory, such as 'C:\OpenCV\' - <PROJECT_ROOT>> <bin> <component> <include> <opencv_classes> <samples> 3.Add the search path for the modules of the project in Delphi IDE (Tools-Options-Delphi Options-Library-Library path) <PROJECT_ROOT>\Include <PROJECT_ROOT>\Include\core <PROJECT_ROOT>\Include\highgui <PROJECT_ROOT>\Include\imgproc <PROJECT_ROOT>\Include\legacy <PROJECT_ROOT>\Include\nonfree <PROJECT_ROOT>\Include\objdetect <PROJECT_ROOT>\Include\calib3d <PROJECT_ROOT>\Include\contrib <PROJECT_ROOT>\Include\video <PROJECT_ROOT>\Include\ml <PROJECT_ROOT>\Include\stitching <PROJECT_ROOT>\component where <PROJECT_ROOT> directory, which was unzipped project. Additionally, you can specify the path to the library header files FFMPEG <PROJECT_ROOT>\Include\ffmpeg <PROJECT_ROOT>\Include\ffmpeg\ctypes <PROJECT_ROOT>\Include\ffmpeg\libavcodec <PROJECT_ROOT>\Include\ffmpeg\libavfilter <PROJECT_ROOT>\Include\ffmpeg\libavformat <PROJECT_ROOT>\Include\ffmpeg\libavutil <PROJECT_ROOT>\Include\ffmpeg\libswscale Examples of using FFMPEG library header files are in the <PROJECT_ROOT>\Delphi-OpenCV-master\Include\ffmpeg\examples 4.Open in Delphi IDE and compile: Examples of the use of certain functions and procedures <PROJECT_ROOT>\samples\LibDemo.groupproj Examples of the use of video processing algorithms <PROJECT_ROOT>\samples\MultiDemo.groupproj Examples of the use of video processing algorithms using VCL.Forms <PROJECT_ROOT>\samples\VCLDemo.groupproj Examples of use of components. To install the components, open and install <PROJECT_ROOT>\Include\component\OpenCV.dpk <PROJECT_ROOT>\samples\ComponentDemo.groupproj
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值