你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。
这个大家都很熟练了,网上有很多介绍,选择C++以及扩展就行
在这里我选择的是visual studio 2019 community版本
新建一个项目,然后扩展
安装qt visual studio tools
安装后关闭vs,退出
点击modify进行安装
方法一:打开cmd,进入目录C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\extras\demo_suite,输入nvcc -V:
方法二:运行测试demo,打开 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\extras\demo_suite,运行deviceQuery.exe:
若显示Result = PASS,说明安装成功。
顺便看一下算力是多少,像我随便找了个k420的板子,算力就是3.0,这个值也可以在https://developer.nvidia.com/zh-cn/cuda-gpus#compute 上找到,但是还是安装以后再看比较准。
https://blog.csdn.net/stjuliet/article/details/107812875
照着上面这个做,能够正确配置,首先要配置好vs2019,cuda和cudnn,然后安装opencv,opencv_contribute,最后再进行cmake,然后再进行编译,才能够全部成功
如:
等等,可以用前人的方法:
https://blog.csdn.net/sazass/article/details/108406518
https://blog.csdn.net/pzb19841116/article/details/115519158
https://blog.csdn.net/weixin_45645281/article/details/114937793
C:\Qt\5.15.2\msvc2019_64\bin
C:\Qt\Tools\CMake_64\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\libnvvp
C:\Program Files\NVIDIA Corporation\Nsight Compute 2021.2.1
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\lib\x64
D:\work\OpenCV\opencv\contrib_new\install\x64\vc16\bin
配置好包含目录和库目录
如下图,建议新建两个opencv的属性表,分别配置debug和release的属性
下面是release的包含目录和库目录配置。选择的是install里面的指定目录,链接器用的是不带d的库lib。
#include
#include
using namespace std;
using namespace cv;
using namespace cv::cuda;
int main()
{
/*-------------------------以下四种验证方式任意选取一种即可-------------------------*/
//获取显卡简单信息
cuda::printShortCudaDeviceInfo(cuda::getDevice()); //有显卡信息表示GPU模块配置成功
//获取显卡详细信息
cuda::printCudaDeviceInfo(cuda::getDevice()); //有显卡信息表示GPU模块配置成功
//获取显卡设备数量
int Device_Num = cuda::getCudaEnabledDeviceCount();
cout << Device_Num << endl; //返回值大于0表示GPU模块配置成功
//获取显卡设备状态
cuda::DeviceInfo Device_State;
bool Device_OK = Device_State.isCompatible();
cout << "Device_State: " << Device_OK << endl; //返回值大于0表示GPU模块配置成功
system("pause");
return 0;
}
测试出结果
#include
#include
#include
#include
using namespace cv;
using namespace std;
bool stop = false;
void sigIntHandler(int signal)
{
stop = true;
cout << "Honestly, you are out!" << endl;
}
int main()
{
Mat img_1 = imread("opencv-logo-white.png");
Mat img_2 = imread("pic5.png");
if (!img_1.data || !img_2.data)
{
cout << "error reading images " << endl;
return -1;
}
int times = 0;
double startime = cv::getTickCount();
signal(SIGINT, sigIntHandler);
int64 start, end;
double time;
vector recognized;
vector scene;
for (times = 0; !stop; times++)
{
start = getTickCount();
recognized.resize(500);
scene.resize(500);
Mat d_srcL, d_srcR;
Mat img_matches, des_L, des_R;
cvtColor(img_1, d_srcL, COLOR_BGR2GRAY);
cvtColor(img_2, d_srcR, COLOR_BGR2GRAY);
Ptr d_orb = ORB::create(500, 1.2f, 6, 31, 0, 2);
Mat d_descriptorsL, d_descriptorsR, d_descriptorsL_32F, d_descriptorsR_32F;
vector keyPoints_1, keyPoints_2;
Ptr d_matcher = DescriptorMatcher::create(cv::DescriptorMatcher::MatcherType::BRUTEFORCE_HAMMING); //cv::DescriptorMatcher::MatcherType:://NORM_L2); MatcherType
std::vector matches;
std::vector good_matches;
d_orb->detectAndCompute(d_srcL, Mat(), keyPoints_1, d_descriptorsL);
d_orb->detectAndCompute(d_srcR, Mat(), keyPoints_2, d_descriptorsR);
d_matcher->match(d_descriptorsL, d_descriptorsR, matches);
int sz = matches.size();
double max_dist = 0; double min_dist = 100;
for (int i = 0; i < sz; i++)
{
double dist = matches[i].distance;
if (dist < min_dist) min_dist = dist;
if (dist > max_dist) max_dist = dist;
}
cout << "\n-- Max dist : " << max_dist << endl;
cout << "\n-- Min dist : " << min_dist << endl;
for (int i = 0; i < sz; i++)
{
if (matches[i].distance < 0.6 * max_dist)
{
good_matches.push_back(matches[i]);
}
}
for (size_t i = 0; i < good_matches.size(); ++i)
{
scene.push_back(keyPoints_2[good_matches[i].trainIdx].pt);
}
for (unsigned int j = 0; j < scene.size(); j++)
cv::circle(img_2, scene[j], 2, cv::Scalar(0, 255, 0), 2);
imshow("img_2", img_2);
waitKey(1);
end = getTickCount();
time = (double)(end - start) * 1000 / getTickFrequency();
cout << "Total time : " << time << " ms" << endl;
if (times == 1000)
{
double maxvalue = (cv::getTickCount() - startime) / cv::getTickFrequency();
cout << "zhenshu " << times / maxvalue << " zhen" << endl;
}
cout << "The number of frame is : " << times << endl;
}
return 0;
}
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
try {
cv::Mat src_host = cv::imread("pic5.png", cv::IMREAD_GRAYSCALE); //LOAD_IMAGE_GRAYSCALE);//这里使用自己的测试图片
cv::cuda::GpuMat dst, src;
src.upload(src_host);
cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY);
cv::Mat result_host;
dst.download(result_host);
cv::imshow("Result", result_host);
cv::waitKey();
}
catch (const cv::Exception& ex)
{
std::cout << "Error:" << ex.what() << std::endl;
}
std::cin.get();
return 0;
}
后面点快了,忘记保存了,就一直下一步基本上就可以,除非中间有需要修改的,比如是否要把所有大写都变成小写等等。