首页 > 编程知识 正文

python爬虫实例,python3.7

时间:2023-05-06 10:04:26 阅读:34245 作者:885

#需要部署模块: import cv [as别名]

#或: from cv import CvtColor [as别名]

defrun(self ) :

while True:

t1=time.time (

# blurthesourceimagetoreducecolornoise

cv.smooth(img,img,cv.CV_BLUR,3 );

#转换主题同步(hue,Saturation,Value ) so its

# easiertodeterminethecolortotrack (hue ) )。

HSV _ img=cv.create image (cv.getsize (img ),8,3 ) ) ) ) ) ) ) )。

cv.cvtcolor(img,hsv_img,cv.CV_BGR2HSV )。

# limitallpixelsthatdon ' tmatchourcriteria,in this case we are

# lookingforpurplebutifyouwantyoucanadjustthefirstvaluein

# bothturpleswhichisthehuerange (120,140 ).OpenCV uses 0-180 as

#a hue range for the HSV color model

threshold ed _ img=cv.create image (cv.getsize (HSV _ img ),8,1 ) ) ) ) ) ) ) )。

#白色

敏感性=10

cv .适当的心情(hsv_img,) 0,0,255-sensitivity,) 255,sensitivity,255 ),thresholded_img ) ) )。

# Red

#cv .适当的心情(hsv_img,(0,150,0 ),() 5,255,thresholded_img ) ) ) ) ) ) ) ) )。

#蓝色

#cv .适当的心情(hsv_img,) 100,50,50 ),) 140,255,255 ),thresholded_img () ) ) ) ) ) ) )。

#绿色

#cv .适当的心情(hsv_img,) 40,50,50 ),) 80,255,255 ),thresholded_img ) ) ) ) ) )。

# determinetheobjectsmomentsandcheckthattheareaislarge

#enough to be our object

moments=cv.moments(mat,0 ) )。

area=cv.HP DSB (运动,0,0 ) ) ) ) ) ) ) )。

# therecanbenoiseinthevideosoignoreobjectswithsmallareas

if(area10000 ) :

# determinethexandycoordinatesofthecenteroftheobject

# wearetrackingbydividingthe 1,0 and 0,1 momentsbythearea

x=cv .令人担心的栗子(moments,1,0 )/area

x=int(round ) x )

# createanoverlaytomarkthecenterofthetrackedobject

(cv.circle(Overlay,) x,y ),2,),255,255 ),20 ) ) ) ) ) ) )

cv.add(img,overlay,img ) )。

# addthethresholdedimagebacktotheimgsowecanseewhatwas

#left after it was applied

t2=time.time (

cv.merge(Thresholded_img,None,None,None,img ) )。

打印'检测时间=% GS x=% d,y=% d ' % (运行(T2-t1,3 ),x,y ) ) ) ) ) ) )

#display the image

cv.show image (color _ tracker _ window,img ) )。

ifcv.waitkey(10 )==27:

布雷克

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。