光流法draw_flow()函数报错

 import cv2
from scipy import * def draw_flow(im, flow, step=16):
""" Plot optical flow at sample points
spaced step pixels apart. """
h, w = im.shape[:2]
y, x = mgrid[step / 2:h:step, step / 2:w:step].reshape(2, -1)
fx,fy = flow[y, x].T
# create line endpoints
lines = vstack([x, y, x + fx, y + fy]).T.reshape(-1, 2, 2)
lines = int32(lines)
# create image and draw
vis = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)
for (x1, y1), (x2, y2) in lines:
cv2.line(vis, (x1, y1), (x2, y2), (0, 255, 0), 1)
cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1)
return vis
# setup video capture
cap = cv2.VideoCapture(0)
ret, im = cap.read()
prev_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
while True:
# get grayscale image
ret, im = cap.read()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# compute flow
flow = cv2.calcOpticalFlowFarneback(prev_gray, gray, None, 0.5, 3, 15, 3, 5, 1.2, 0)
prev_gray = gray
# plot the flow vectors
cv2.imshow('Optical flow', draw_flow(gray, flow))
if cv2.waitKey(10) == 27:
break

报错:

解决方案行加上.astype(int)就解决了

y, x = mgrid[step / 2:h:step, step / 2:w:step].reshape(2, -1).astype(int) #以网格的形式选取二维图像上等间隔的点,这里间隔为16,reshape成2行的array

光流法draw_flow()函数报错的更多相关文章

  1. js执行函数报错Cannot set property 'value' of null怎么解决?

    js执行函数报错Cannot set property 'value' of null 的解决方案: 原因:dom还没有完全加载 第一步:所以js建议放在body下面执行, 第二步:window.on ...

  2. python 3 直接使用reload函数报错

    reload()是python2 的内置函数可以直接使用,但是python3 直接使用此函数报错,需要导入importlib 模块 from importlib import reload

  3. Linux 下使用C语言 gets()函数报错

    在Linux下,使用 gets(cmd) 函数报错:warning: the 'gets' function is dangerous and should not be used. 解决办法:采用 ...

  4. C++ socket bind()函数报错 不存在从 "std::_Binder<std::_Unforced, SOCKET &, sockaddr *&, size_t &>" 到 "int" 的适当转换函数

    昨天还可以正常运行的程序,怎么今天改了程序的结构就报错了呢?我明明没有改动函数内部啊!!! 内心无数只“草泥马”在奔腾,这可咋办呢?于是乎,小寅开始求助于亲爱的度娘...... 由于小寅知识水平有限, ...

  5. updatexml和extractvalue函数报错注入

    updatexml()函数报错注入 updatexml (XML_document, XPath_string, new_value); 第一个参数:XML_document是String格式,为XM ...

  6. php 升级到 5.3+ 后出现的一些错误,如 ereg(); ereg_replace(); 函数报错

    在php5.3环境下运行,常常会出现 Deprecated: Function ereg() is deprecated in...和Deprecated: Function ereg_replace ...

  7. PHP empty函数报错的解决办法

    PHP empty函数在检测一个非变量情况下报错的解决办法. PHP开发时,当你使用empty检查一个函数返回的结果时会报错:Fatal error: Can't use function retur ...

  8. Linux下编译C代码,出现tan函数报错的情况

    undefined reference to `tan' 但是已经包含了头文件 <math.h>了,可还是报错,说是找不到tan 这个问题的原因不是很清楚, 但是网上给出的方案,就是编译的 ...

  9. geopandas overlay 函数报错问题解决方案

    前言 这篇文章依旧是基于上一篇文章(使用Python实现子区域数据分类统计)而写,此文章中介绍了使用 geopandas 的 overlay 函数对两个 GeoDataFrame 对象取相交或相异的部 ...

随机推荐

  1. windows下使用cmake+mingw配置makefile

    前面一节说了cmake简易使用,但是实际开发中项目文件非常多,使用哪种简易方式会导致代码十分混乱,因此本文介绍一种cmake管理大型项目的demo流程. 具体步骤如下: 1.创建相关的项目目录 cmd ...

  2. LeetCode111_求二叉树最小深度(二叉树问题)

    题目: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the s ...

  3. jsqlparser和calcite和druid功能对比

    需求分析:(用其它方法替代metabase中的某些功能)功能1.通过对sql查询语句的分析,得到所有表名,以及所有表的字段名,字段类型,字段注解信息.功能2.在sql语句执行查询前,校验sql语句是否 ...

  4. The first day of Crawler learning

    使用BeautifulSoup解析网页 Soup = BeautifulSoup(urlopen(html),'lxml') Soup为汤,html为食材,lxml为菜谱 from bs4 impor ...

  5. 20191024-3 互评Alpha阶段作品——胜利点组

    此作业要求参见 https://edu.cnblogs.com/campus/nenu/2019fall/homework/9860 基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评 ...

  6. $[SHOI2007]$ 园丁的烦恼 二维数点/树状数组

    \(Sol\) 设一个矩阵的左上角为\((x_1,y_1)\),右下角为\((x_2,y_2)\),\(s_{x,y}\)是到\((1,1)\)二维前缀和,那么这个矩阵的答案显然是\(s_{x_2,y ...

  7. 智能反射表面(可重构智能表面)Large Intelligent surface 最新综述整理

    闻道洛阳花正好,家家遮户春风.道人饮处百壶空.年年花下醉,看尽几番红. 此拐又从何处去,飘蓬一任西东.语声虽异笑声同.一轮清夜月,何处不相逢. ---- 临江仙·与刘拐 更多精彩内容请关注微信公众号 ...

  8. java poi ppt 接口的基本操作

    依赖 在 pom.xml中增加以下依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId& ...

  9. [UWP]XAML中的响应式布局技术

    响应式布局的概念是一个页面适配多个终端及不同分辨率.在针对特定屏幕宽度优化应用 UI 时,我们将此称为创建响应式设计.WPF设计之初响应式设计的概念并不流行,那时候大部分网页设计师都按着宽度960像素 ...

  10. Linux Centos7 环境搭建Docker部署Zookeeper分布式集群服务实战

    Zookeeper完全分布式集群服务 准备好3台服务器: [x]A-> centos-helios:192.168.19.1 [x]B-> centos-hestia:192.168.19 ...