如何使用opencv中的UpdateMotionhistory函数修复此错误
How can i fix this error with my UpdateMotionhistory function in opencv?
我了解了opencv中的updatemotionhistory函数,并想过尝试一下。但由于某种原因,我收到了这个错误"opencv错误:错误标志(参数或结构字段)(无法识别或不支持ed数组类型),文件C:\builds\2_4_PackSlave-win64-vc11-shared\opencv\modules\core\src\array.cpp,第2482行。
我注意到这个错误发生在我实现updatemotionhistory函数之后,这让我认为我可能在updatemotionhistory函数中输入参数时犯了错误。
这是我的代码:-
Mat frame,dst,tst;
double timestamp = (double)clock()/CLOCKS_PER_SEC; // I found this in the Opencv/samples motempl.cpp
double duration = 1; //same as above , found this value in the opencv/samples/motempl.cpp
videocapture cap(0);
while(1)
{
cap.read(frame);
cvtColor(frame,frame,CV_BGR2GRAY);
cap.read(dst);
cvtColor(dst,dst,CV_BGR2GRAY);
absdiff(frame,dst,frame2);
imshow("absolute frame difference",frame2);
threshold(frame2,frame2,60,255,THRESH_BINARY);
imshow("threshold",frame2);
updateMotionHistory(frame2,tst,cap_timestamp,duration);
waitkey(30);
}
我有两个问题:-如何准确地获得updatemotionhistory函数的时间戳值和持续时间值?我已经了解到,我们可以将时间戳值设置为(int cap_timestamp=cap.get(CV_cap_PROP_POS_MSEC),以及如何设置持续时间值?
让我们看看文档:
void updateMotionHistory(InputArray silhouette,
InputOutputArray mhi,
double timestamp,
double duration)
mhi
是
单通道、32位浮点
因此,用CV_32FC1声明您的tst
,例如Mat tst(frameHeight, frameWidth CV_32FC1);
,可以解决OpenCV错误。
timestamp
和duration
定义了应用程序的"历史记录"。timestamp
的意思是"现在",这是一个随着时间的推移而增长的数字;duration
表示"要存储在mhi
(运动历史图像)中的历史长度",这是一个常数。
让我们来看一个简单的一维移动球(B):
B
---|---|---|---|---|--->
0 1 2 3 4 x
假设球每次向右移动一个。在时间1,球在:
B
---|---|---|---|---|--->
0 1 2 3 4 x
时间(stamp)1的剪影(absdiff,与您的代码中相同)为[True,True,False,False,False]。假设mhi
的初始值为[0,0,0,0],duration
为2:
timestamp silhouette mhi
1 [T, T, F, F, F] --> [1, 1, 0, 0, 0]
2 [F, T, T, F, F] --> [1, 2, 2, 0, 0]
3 [F, F, T, T, F] --> [1, 2, 3, 3, 0]
4 [F, F, F, T, T] --> [0, 2, 3, 4, 4]
...
CCD_ 11存储时间戳的历史。例如,mhi[x] == t
表示"当时间戳为t时,球在位置x移动。"
根据您在应用程序中对"历史"的定义,您可以定义自己的timestamp
和duration
。如果你不知道如何确定这两个参数,这里有两个简单的例子:
timestamp = clock(); duration = 5000 ms;
使用实时作为时间戳,存储最后5秒的历史记录timestamp = frameNumber(); duration = 50 frames;
使用视频帧号作为时间戳,存储最后50帧的历史。frameNumber()
只是在while(1)
循环中返回timestamp + 1.0
- 链接器错误:函数的多个定义
- 编译器错误:函数调用在常量表达式中必须有一个常量值
- 错误:函数声明符之后的预期函数体
- C 错误 - 函数不能超载
- 如何修复传递参数时调用错误函数的主函数?(C++)
- 错误:函数调用中有两个参数
- 错误:函数不是“类”的静态数据成员 - C++
- C ,G 编译错误函数
- CMake 解析错误函数缺少结尾")"。而是找到带有文本的未终止字符串")
- C++ 错误 函数 2 的多重定义
- 错误:函数调用中从int到int(*)[4]的转换无效
- C++14 自动扣除错误:函数返回一个数组
- 视觉C++错误:函数必须返回一个值
- 错误:函数声明中的两种或多种数据类型
- 错误:函数未在作用域中声明
- rtw_android.c错误:函数“strnicmp”的隐式声明[-Weror=隐式函数声明]
- 错误:函数中的return语句没有值,返回“void*”[-fpermission]
- 简单程序中的链接器错误:函数的多重定义
- 错误:函数参数太多
- 错误:函数__tmaincrtstartup中引用的未解析的外部符号_main