1、如果你是某BNUer,还在为某多媒体课的作业而烦恼,那么看看我这篇文章或许能够帮助你成功肝完DDL! 2、如果你只是想尝试一下Laplace做边缘检测,那么走过路过不要错过,看看我这篇文章真的是来对地方了!
一、实验要求
实验要求: 从AVI文件( bsd.avi)中得到视频流,对视频流进行Laplace边缘检测,并输出结果。 注: 1、Laplace边缘检测 2、主要思想
实验环境: OpenCV2.4.13.6 + visual studio 2019
二、实验环境配置
1、visual studio + OpenCV的配置
(1)环境说明
笔者使用的实验环境是 visual studio 2019 + OpenCV 2.4.13.6。visual studio的安装教程网上有很多,在此就不多bb怎么安装了。这里主要以visual studio 2019为例来讲解如何配置OpenCV 2.4.13.6。各版本配置的方法都差不多,但是需要搜索和下载对应的OpenCV版本,不然的话容易出现一些问题。
如果是其他版本的VS和opencv可以参考一下这个链接https://blog.csdn.net/xinjiang666/article/details/80785210
(2)OpenCV的下载
方式1 :点击下载Opencv2.4.13.6安装包 方式2 :点击官网下载对应版本
(3)OpenCV的配置
1、双击下载好的OpenCV 2、选择好全英文路径并点击Extract 3、可以看到E:\OpenCV\路径下已经有了一个叫opencv的目录 4、点击进去可以看到opencv中包含的内容 5、添加系统环境变量(x64的版本) 此电脑(我的电脑)——>右键——>属性——>高级系统设置——>环境变量——>系统变量——>path——>编辑——>新建,然后添加刚才opencv目录下对应到bin的路径 6、打开visual studio 2019,点击创建新项目,新建C++控制台应用程序 7、将下图中的x86改为x64 8、视图–>其他窗口–>属性管理器。 9、Debug | x64 ——>右键——>添加新项目属性表 10、添加包含目录 右键刚才新建的属性表——>属性——>VC++目录——>包含目录 添加下面的三个路径(需要根据自己opencv路径自行修改): 11、添加库目录 VC++目录——>库目录——>编辑
12、添加附加依赖项 链接器——>输入——>附加依赖项,可以将下面的内容直接复制到附加依赖项中
opencv_calib3d2413d.lib opencv_contrib2413d.lib opencv_core2413d.lib opencv_features2d2413d.lib opencv_flann2413d.lib opencv_gpu2413d.lib opencv_highgui2413d.lib opencv_imgproc2413d.lib opencv_legacy2413d.lib opencv_ml2413d.lib opencv_nonfree2413d.lib opencv_objdetect2413d.lib opencv_ocl2413d.lib opencv_photo2413d.lib opencv_stitching2413d.lib opencv_superres2413d.lib opencv_video2413d.lib opencv_videostab2413d.lib
好的,进行完这一步,说明已经将环境配置好了,接下来可以尝试运行代码了,nice!
三、运行源代码
1、出现的问题及解决方法
(1)运行代码时出现了如下问题
warning MSB8003: 未定义 WindowsSDKDir 属性。可能找不到某些生成工具
(2)解决方法
参考https://blog.csdn.net/dongbao520/article/details/117289543
用Visual Studio Installer进行修复
2、从AVI文件中得到视频流,进行laplace边缘检测的代码 :
#include "cv.h"
#include "highgui.h"
#include <ctype.h>
#include <stdio.h>
int main(int argc, char** argv)
{
IplImage* laplace = 0;
IplImage* colorlaplace = 0;
IplImage* planes[3] = { 0, 0, 0 };
CvCapture* capture = 0;
capture = cvCaptureFromAVI( "E://1qq document//bsd.avi" );
if (!capture)
{
fprintf(stderr, "Could not initialize capturing.../n");
return -1;
}
cvNamedWindow("Laplacian", 0);
for (;;)
{
IplImage* frame = 0;
int i;
frame = cvQueryFrame(capture);
if (!frame)
break;
if (!laplace)
{
for (i = 0; i < 3; i++)
planes[i] = cvCreateImage(cvSize(frame->width, frame->height), 8, 1);
laplace = cvCreateImage(cvSize(frame->width, frame->height),
IPL_DEPTH_16S, 1);
colorlaplace = cvCreateImage(cvSize(frame->width, frame->height), 8, 3);
}
cvCvtPixToPlane(frame, planes[0], planes[1], planes[2], 0);
for (i = 0; i < 3; i++)
{
cvLaplace(planes[i], laplace, 3);
cvConvertScaleAbs(laplace, planes[i], 1, 0);
}
cvCvtPlaneToPix(planes[0], planes[1], planes[2], 0, colorlaplace);
colorlaplace->origin = frame->origin;
cvShowImage("Laplacian", colorlaplace);
if (cvWaitKey(10) >= 0)
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Laplacian");
return 0;
}
3、从摄像头中得到视频流进行laplace边缘检测的代码 :
#include "cv.h"
#include "highgui.h"
#include <ctype.h>
#include <stdio.h>
int main(int argc, char** argv)
{
IplImage* laplace = 0;
IplImage* colorlaplace = 0;
IplImage* planes[3] = { 0, 0, 0 };
CvCapture* capture = 0;
if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
capture = cvCaptureFromCAM(argc == 2 ? argv[1][0] - '0' : 0);
else if (argc == 2)
capture = cvCaptureFromAVI(argv[1]);
if (!capture)
{
fprintf(stderr, "Could not initialize capturing.../n");
return -1;
}
cvNamedWindow("Laplacian", 0);
for (;;)
{
IplImage* frame = 0;
int i;
frame = cvQueryFrame(capture);
if (!frame)
break;
if (!laplace)
{
for (i = 0; i < 3; i++)
planes[i] = cvCreateImage(cvSize(frame->width, frame->height), 8, 1);
laplace = cvCreateImage(cvSize(frame->width, frame->height),
IPL_DEPTH_16S, 1);
colorlaplace = cvCreateImage(cvSize(frame->width, frame->height), 8, 3);
}
cvCvtPixToPlane(frame, planes[0], planes[1], planes[2], 0);
for (i = 0; i < 3; i++)
{
cvLaplace(planes[i], laplace, 3);
cvConvertScaleAbs(laplace, planes[i], 1, 0);
}
cvCvtPlaneToPix(planes[0], planes[1], planes[2], 0, colorlaplace);
colorlaplace->origin = frame->origin;
cvShowImage("Laplacian", colorlaplace);
if (cvWaitKey(10) >= 0)
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Laplacian");
return 0;
}
四、参考资料
- https://blog.csdn.net/lzheng012019/article/details/121531472
- https://blog.csdn.net/jishijian7408/article/details/100690253?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163806819216780271992167%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163806819216780271992167&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-4-100690253.first_rank_v2_pc_rank_v29&utm_term=vs2010%E9%85%8D%E7%BD%AEopencv2.4&spm=1018.2226.3001.4449
- https://blog.csdn.net/xinjiang666/article/details/80785210?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_utm_term~default-0.no_search_link&spm=1001.2101.3001.4242.1
- https://www.cnblogs.com/gao-hongxiang/p/12342419.html
- https://blog.csdn.net/dongbao520/article/details/117289543
|