Python基础之opencv框架

Python中的opencv框架

程序举例演示:

[python] view plain copy

  1. import cv2
  2. img=cv2.imread('1.jpg')
  3. cv2.imshow('image',img)
  4. cv2.waitKey(0)
  5. #转为灰度图
  6. img=cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
  7. cv2.imshow('image',img)
  8. cv2.waitKey(0)
  9. cv2.destroyAllWindows()

执行程序:

Python基础之opencv框架

灰度图:

Python基础之opencv框架

在图片上划线:

[python] view plain copy

  1. import cv2
  2. img=cv2.imread('1.jpg')
  3. #在图片上划线
  4. green=(0,255,0)
  5. cv2.line(img,(0,0),(900,900),green,9)
  6. cv2.imshow('img',img)
  7. cv2.waitKey(0)
  8. cv2.destroyAllWindows()

执行程序结果:

Python基础之opencv框架

在图片上画圆:

[python] view plain copy

  1. import cv2
  2. img=cv2.imread('1.jpg')
  3. #在图片上画圆
  4. green=(0,255,0)
  5. cv2.circle(img,(300,300),100,green,20)
  6. cv2.imshow('img',img)
  7. cv2.waitKey(0)
  8. cv2.destroyAllWindows()

程序执行效果:

在图片上画矩形:

[python] view plain copy

  1. import cv2
  2. img=cv2.imread('1.jpg')
  3. #在图片上画矩形,四元组组成,左上角坐标点和右下角坐标点
  4. green=(0,255,0)
  5. cv2.rectangle(img,(200,100),(300,200),green,3)
  6. cv2.imshow('img',img)
  7. cv2.waitKey(0)
  8. cv2.destroyAllWindows()

执行程序:

Python基础之opencv框架

相关推荐