我从上面得到这个错误,不知道如何避免它.我的目标是获取屏幕截图,然后在其上执行模板匹配,以查看此时屏幕上是否显示图标.直到现在它只是图标的位置.我的代码:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <Windows.h>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
using namespace cv;
Mat hwnd2mat();
/// Global Variables
Mat img; Mat templ; Mat result;
int main()
{
/// Load image and template
templ = imread( "Template.bmp",1);
templ.convertTo(templ, CV_8U);
//img = imread( "Image.jpg", 1 );
img = hwnd2mat();
/// Create the result matrix
int result_cols = img.cols - templ.cols + 1;
int result_rows = img.rows - templ.rows + 1;
result.create( result_cols, result_rows, CV_8U); …Run Code Online (Sandbox Code Playgroud) 需要帮助我尝试使用OpenCV加载和转换图像:
这是我的代码:
templ = imread("Template.bmp",-1);
cout<<"templ before convert: "<<type2str(templ.type())<<endl;
templ.convertTo(templ,CV_8UC4);
cout<<"templ after convert: "<<type2str(templ.type())<<endl;
Run Code Online (Sandbox Code Playgroud)
这给了我CV_8UC3!图像不是用于转换为4个通道或类似的东西吗?或者我需要一个比例因子(读到这样的事情)?
感谢您的帮助,最好的问候!