本文实例为大家分享了python+opencv识别图片中足球的方法,供大家参考,具体内容如下
先补充下霍夫圆变换的几个参数知识:
源代码:
# -*- coding: utf-8 -*- """ Created on Tue Sep 26 23:15:39 2017 @author: tina """ import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread('C://Users//tina//Pictures//ahh//ball.jpg') gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) plt.subplot(121),plt.imshow(gray,'gray') plt.xticks([]),plt.yticks([]) circles1 = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1, 600,param1=100,param2=30,minRadius=80,maxRadius=97) circles = circles1[0,:,:] circles = np.uint16(np.around(circles)) for i in circles[:]: cv2.circle(img,(i[0],i[1]),i[2],(255,0,0),5) cv2.circle(img,(i[0],i[1]),2,(255,0,255),10) cv2.rectangle(img,(i[0]-i[2],i[1]+i[2]),(i[0]+i[2],i[1]-i[2]),(255,255,0),5) print("圆心坐标",i[0],i[1]) plt.subplot(122),plt.imshow(img) plt.xticks([]),plt.yticks([])
原图:
识别后效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持VEVB武林网。
新闻热点
疑难解答