gpt4 book ai didi

c++ - OpenCV.norm 断言错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:48 26 4
gpt4 key购买 nike

我在汉明距离的帮助下寻找视频中两个图像的差异。这是我的代码:

#include <iostream>
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char** argv)
{
char const* filename = ("video.mp4");
VideoCapture video(filename);
Mat frame, temp;
for(unsigned int i = 0; i<100; i++)
{
video >> frame;
if (i > 0)
{
double dist = norm(frame, temp, NORM_HAMMING);
cout<<"Dist= "<< dist <<endl;
}
temp = frame;
}
return 0;
}

问题是在

double dist = norm(frame, temp, NORM_HAMMING);

程序属于

**OpenCV Error**: Assertion failed (normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U))in norm, in file /home/andrio/.local/share/Trash/files/build/OpenCV/modules/core/src/stat.cpp, line 3123 terminate called after throwing an instance of 'cv::Exception' what():  /home/andre/.local/share/Trash/files/build/OpenCV/modules/core/src/stat.cpp:3123: error: (-215) normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U) in function norm

UPD:此代码有效:

double dist = norm(frame, temp, NORM_L2);

最佳答案

你需要把图像调成灰色

cvtColor(frame, frame, CV_BGR2GRAY);

关于c++ - OpenCV.norm 断言错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37056993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com