# 需要導入模塊: import cv [as 別名]

# 或者: from cv import CvtColor [as 別名]

def run(self):

while True:

img = cv.QueryFrame( self.capture )

t1 = time.time()

#blur the source image to reduce color noise

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

#convert the image to hsv(Hue, Saturation, Value) so its

#easier to determine the color to track(hue)

hsv_img = cv.CreateImage(cv.GetSize(img), 8, 3)

cv.CvtColor(img, hsv_img, cv.CV_BGR2HSV)

#limit all pixels that don't match our criteria, in this case we are

#looking for purple but if you want you can adjust the first value in

#both turples which is the hue range(120,140). OpenCV uses 0-180 as

#a hue range for the HSV color model

thresholded_img = cv.CreateImage(cv.GetSize(hsv_img), 8, 1)

# White

sensitivity = 10

cv.InRangeS(hsv_img, (0, 0, 255-sensitivity), (255, sensitivity, 255), thresholded_img)

# Red

#cv.InRangeS(hsv_img, (0, 150, 0), (5, 255, 255), thresholded_img)

# Blue

#cv.InRangeS(hsv_img, (100, 50, 50), (140, 255, 255), thresholded_img)

# Green

#cv.InRangeS(hsv_img, (40, 50, 50), (80, 255, 255), thresholded_img)

#determine the objects moments and check that the area is large

#enough to be our object

mat=cv.GetMat(thresholded_img)

moments = cv.Moments(mat, 0)

area = cv.GetCentralMoment(moments, 0, 0)

#there can be noise in the video so ignore objects with small areas

if(area > 10000):

#determine the x and y coordinates of the center of the object

#we are tracking by dividing the 1, 0 and 0, 1 moments by the area

x = cv.GetSpatialMoment(moments, 1, 0)/area

y = cv.GetSpatialMoment(moments, 0, 1)/area

x = int(round(x))

y = int(round(y))

#create an overlay to mark the center of the tracked object

overlay = cv.CreateImage(cv.GetSize(img), 8, 3)

cv.Circle(overlay, (x, y), 2, (255, 255, 255), 20)

cv.Add(img, overlay, img)

#add the thresholded image back to the img so we can see what was

#left after it was applied

t2 = time.time()

cv.Merge(thresholded_img, None, None, None, img)

print "detection time = %gs x=%d,y=%d" % ( round(t2-t1,3) , x, y)

#display the image

cv.ShowImage(color_tracker_window, img)

if cv.WaitKey(10) == 27:

break

python的cvtcolor_Python cv.CvtColor方法代碼示例相关推荐

  1. python datetime datetime_Python datetime.tzinfo方法代碼示例

    本文整理匯總了Python中datetime.datetime.tzinfo方法的典型用法代碼示例.如果您正苦於以下問題:Python datetime.tzinfo方法的具體用法?Python da ...

  2. python execute_command err_Python management.execute_from_command_line方法代碼示例

    本文整理匯總了Python中django.core.management.execute_from_command_line方法的典型用法代碼示例.如果您正苦於以下問題:Python manageme ...

  3. python template languages_Python template.TemplateSyntaxError方法代碼示例

    本文整理匯總了Python中django.template.TemplateSyntaxError方法的典型用法代碼示例.如果您正苦於以下問題:Python template.TemplateSynt ...

  4. python time strptime_Python time.strptime方法代碼示例

    本文整理匯總了Python中time.strptime方法的典型用法代碼示例.如果您正苦於以下問題:Python time.strptime方法的具體用法?Python time.strptime怎麽 ...

  5. python柱状图zzt_Python torch.diag方法代碼示例

    本文整理匯總了Python中torch.diag方法的典型用法代碼示例.如果您正苦於以下問題:Python torch.diag方法的具體用法?Python torch.diag怎麽用?Python ...

  6. python的concatetate_Python tensorflow.truncated_normal_initializer方法代碼示例

    本文整理匯總了Python中tensorflow.truncated_normal_initializer方法的典型用法代碼示例.如果您正苦於以下問題:Python tensorflow.trunca ...

  7. python turtle color_Python turtle.color方法代碼示例

    本文整理匯總了Python中turtle.color方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.color方法的具體用法?Python turtle.color怎麽用?P ...

  8. python asyncio future_Python asyncio.ensure_future方法代碼示例

    本文整理匯總了Python中asyncio.ensure_future方法的典型用法代碼示例.如果您正苦於以下問題:Python asyncio.ensure_future方法的具體用法?Python ...

  9. python psutil.disk_Python psutil.disk_partitions方法代碼示例

    本文整理匯總了Python中psutil.disk_partitions方法的典型用法代碼示例.如果您正苦於以下問題:Python psutil.disk_partitions方法的具體用法?Pyth ...

  10. python querystring encode_Java UriUtils.encodeQueryParam方法代碼示例

    import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類 private URI buildURI(OTXEndpoints ...

最新文章

  1. 各种喜好配置【2021.10】
  2. 5. 最长回文子串——基于扩展中心法的优化
  3. 汽车租赁php参考文献,求租赁或者汽车租赁的英文参考文献
  4. 阿里研究员:警惕软件复杂度困局
  5. red hat安装宝塔_只需几分钟即可安装Red Hat Container Development Kit(视频)
  6. 两个excel文档查找相同选项后替换_看似普通的查找和替换功能,用好了,能让你的工作效率翻一番...
  7. mysql myisam 支持事务吗_第三章(附)mysql表类型MyISAM和InnoDB区别(决定了是否支持事务)...
  8. MySQL 外连接查询
  9. 如何妥善处理WebBrowser对Javascript的错误问题,阻止JS弹出框,提高用户体验(原创)...
  10. 【英语学习】【Level 08】U01 Let's Read L3 The classics are always in
  11. Hello word ;
  12. 540.有序数组中的单一元素(力扣leetcode) 博主可答疑该问题
  13. MySql安装版安装最新教程(附错误解决 )
  14. matlab 绘图 模板,【科研绘图】MATLAB可视化代码模板
  15. 经典的机器人入门资料
  16. mysql能够跨平台使用吗_Mysql跨平台(Windows,Linux,Mac)使用与安装
  17. 画色彩如何画出体积感
  18. OA系统的一些学习心得(更新中)
  19. 用javascript计算PPI
  20. slc mlc tlc nand

热门文章

  1. android 电容触摸屏,剖析触摸屏上的电容按键
  2. Mesh网格编程(三) 正12面体
  3. 国内自动化测试软件,AutoRunner-国内测试行业专业自动化测试工具成长史
  4. 含金量高文科竞赛信息资料
  5. 软件测试工程师必备的27个基础技能
  6. 进化计算(八)——MOEA/D算法详解Ⅱ
  7. UML之Astah的基本使用教程-1
  8. C语言二维数组及指针引用
  9. PHP爬虫最全总结1
  10. java文件上传判重姿势浅谈