我已经尝试使用 Otsu 阈值处理实时视频。但是我遇到了这个问题
OpenCV 错误:阈值中的断言失败 (src.type() == CV_8UC1),文件 /home/usr/opencv-3.2.0/modules/imgproc/src/thresh.cpp,第 1356 行终止在抛出实例后调用cv::Exception' what(): /home/usr/opencv-3.2.0/modules/imgproc/src/thresh.cpp:1356: error: (-215) src.type() == CV_8UC1 in function threshold
而且,这是我使用的编码
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/core/mat.hpp>
#include <iostream>
using namespace cv;
const String window_capture_name = "Video Capture";
const String window_capture_thres = "Video Threshold";
int main(int argc, char* argv[]){
VideoCapture cap(0);
namedWindow(window_capture_name);
namedWindow(window_capture_thres);
Mat Thres(1280, 720, CV_8UC4), frame(1280, 720, CV_8UC4), frame_thres(1280, 720, CV_8UC4);
while (true) {
cap >> frame;
Thres = threshold(frame, frame_thres, 0, 255, THRESH_OTSU);
if(frame.empty())
{
break;
}
imshow(window_capture_name, Thres);
imshow(window_capture_thres, frame);
char key = (char) waitKey(30);
if (key == 'q' || key == 27)
{
break;
}
}
return 0;
}