首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OpenCV.norm中的断言错误

OpenCV.norm中的断言错误
EN

Stack Overflow用户
提问于 2016-05-05 17:43:24
回答 1查看 1.2K关注 0票数 1

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

代码语言:javascript
运行
复制
#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; 
 }

问题是在

代码语言:javascript
运行
复制
double dist = norm(frame, temp, NORM_HAMMING);

程序降至

代码语言:javascript
运行
复制
**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:这段代码是工作的:

代码语言:javascript
运行
复制
double dist = norm(frame, temp, NORM_L2);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-06 10:57:24

你需要把图像变成灰色

代码语言:javascript
运行
复制
cvtColor(frame, frame, CV_BGR2GRAY);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37056993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档