光流法draw_flow()函数报错
光流法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()函数报错的更多相关文章
- js执行函数报错Cannot set property 'value' of null怎么解决?
js执行函数报错Cannot set property 'value' of null 的解决方案: 原因:dom还没有完全加载 第一步:所以js建议放在body下面执行, 第二步:window.on ...
- python 3 直接使用reload函数报错
reload()是python2 的内置函数可以直接使用,但是python3 直接使用此函数报错,需要导入importlib 模块 from importlib import reload
- Linux 下使用C语言 gets()函数报错
在Linux下,使用 gets(cmd) 函数报错:warning: the 'gets' function is dangerous and should not be used. 解决办法:采用 ...
- C++ socket bind()函数报错 不存在从 "std::_Binder<std::_Unforced, SOCKET &, sockaddr *&, size_t &>" 到 "int" 的适当转换函数
昨天还可以正常运行的程序,怎么今天改了程序的结构就报错了呢?我明明没有改动函数内部啊!!! 内心无数只“草泥马”在奔腾,这可咋办呢?于是乎,小寅开始求助于亲爱的度娘...... 由于小寅知识水平有限, ...
- updatexml和extractvalue函数报错注入
updatexml()函数报错注入 updatexml (XML_document, XPath_string, new_value); 第一个参数:XML_document是String格式,为XM ...
- php 升级到 5.3+ 后出现的一些错误,如 ereg(); ereg_replace(); 函数报错
在php5.3环境下运行,常常会出现 Deprecated: Function ereg() is deprecated in...和Deprecated: Function ereg_replace ...
- PHP empty函数报错的解决办法
PHP empty函数在检测一个非变量情况下报错的解决办法. PHP开发时,当你使用empty检查一个函数返回的结果时会报错:Fatal error: Can't use function retur ...
- Linux下编译C代码,出现tan函数报错的情况
undefined reference to `tan' 但是已经包含了头文件 <math.h>了,可还是报错,说是找不到tan 这个问题的原因不是很清楚, 但是网上给出的方案,就是编译的 ...
- geopandas overlay 函数报错问题解决方案
前言 这篇文章依旧是基于上一篇文章(使用Python实现子区域数据分类统计)而写,此文章中介绍了使用 geopandas 的 overlay 函数对两个 GeoDataFrame 对象取相交或相异的部 ...
随机推荐
- 转:EBS-自动获取/创建CCID
DECLARE l_ccid NUMBER; l_msg ); l_chart_of_account_id NUMBER; l_set_of_book_id NUMBER; BEGIN l_set_o ...
- Struts2和Spring集成
Spring是一个流行的Web框架,它提供易于集成与很多常见的网络任务.所以,问题是,为什么我们需要Spring,当我们有Struts2?Spring是超过一个MVC框架 - 它提供了许多其它好用的东 ...
- POJ-1741 树上分治--点分治(算法太奇妙了)
给你1e5个节点的树,(⊙﹏⊙) 你能求出又几对节点的距离小于k吗??(分治NB!) 这只是一个板子题,树上分治没有简单题呀!(一个大佬说的) #include<cstdio> #incl ...
- __str__、__repr__和__format__
obj.__ str __ ()是面向用户的,该方法将实例转换为一个字符 obj.__ repr __ ()面向程序员,该方法返回一个实例的代码表示形式,通常用来重新构造这个实例,repr()函数返回 ...
- 20191017-6 alpha week 2/2 Scrum立会报告+燃尽图 05
此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9802 小组名称:“组长”组 组长:杨天宇 组员:魏新,罗杨美慧,王歆瑶,徐 ...
- Java:Excel文件上传至后台
之前的项目中有遇到上传Excel文件的需求,简单说就是解析一个固定格式的Excel表格,然后存到数据库对应的表中,表格如下: 项目采用SSM架构,mvc模式,显而易见,这个Excel表需要拆成两个表, ...
- webpack4的配置你都掌握了么?
webpack5都出了,webpack4的的基本配置,解析ES6,引入CSS,编译Less,设置image等等,你都会了么? 解析ES6 了解Babel Babel是一个JavaScript编译器, ...
- 10.Python中print函数中中逗号和加号的区别
先看看print中逗号和加号分别打印出来的效果.. 这里以Python3为例 1 print("hello" + "world") helloworld 1 p ...
- SQL server 基本语句
--查询数据库是否存在 if exists ( select * from sysdatabases where [name]='TestDB') print 'Yes, the DB exists' ...
- 【tf.keras】Linux 非 root 用户安装 CUDA 和 cuDNN
TensorFlow 2.0 for Linux 使用时报错:(cuDNN 版本低了) E tensorflow/stream_executor/cuda/cuda_dnn.cc:319] Loade ...