【发布时间】:2021-10-04 15:41:57
【问题描述】:
我想生成一个代码,以便在 QR 码指向相机时播放视频。 但我在 warpPerspective 中遇到错误。 错误是:OpenCV(4.5.3) 错误:断言失败 (_src.total() > 0) in cv::warpPerspective, 文件 C:\build\master_winpack-build-win64-vc15\opencv\modules\imgproc \src \imgwarp.cpp,第 3144 行 找了很多地方都找不到答案,所以来问一下。
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
void main()
{
Mat cameraFrame, videoFrame;
vector<Point2f> bbox;
double width, height;
VideoCapture camera(0), video;
QRCodeDetector qrDecoder;
string data;
while (camera.read(cameraFrame))
{
data = qrDecoder.detectAndDecode(cameraFrame, bbox);
if (data.length() > 0)
{
if (!video.isOpened()) {
video.open("../data/"+data+".mp4");
width = video.get(CAP_PROP_FRAME_WIDTH);
height = video.get(CAP_PROP_FRAME_HEIGHT);
}
vector<Point2f> v_bbox{ Point2f(0, 0), Point2f(width,0), Point2f(width,height), Point2f(0, height) };
Mat H = findHomography(v_bbox, bbox);
video >> videoFrame;
Mat warpedFrame, warpedMask;
warpedFrame.copyTo(cameraFrame, warpedMask);
warpPerspective(videoFrame, warpedFrame, H, cameraFrame.size());
Mat mask(videoFrame.size(), CV_8UC1, cv::Scalar(255));
warpPerspective(mask, warpedMask, H, cameraFrame.size());
imshow("warepedFrame", warpedFrame);
imshow("WarpedMask", warpedMask);
}
imshow("cam", cameraFrame);
waitKey(1);
}
}
【问题讨论】: