fifth commit

master
TangSiqin 7 years ago
parent 193967fa81
commit 066364080f

@ -1,28 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{8140A5F2-F504-4A45-BC0F-9308BB211168}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Debug|x64.ActiveCfg = Debug|x64
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Debug|x64.Build.0 = Debug|x64
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Debug|x86.ActiveCfg = Debug|Win32
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Debug|x86.Build.0 = Debug|Win32
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Release|x64.ActiveCfg = Release|x64
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Release|x64.Build.0 = Release|x64
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Release|x86.ActiveCfg = Release|Win32
{8140A5F2-F504-4A45-BC0F-9308BB211168}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

@ -1,154 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8140A5F2-F504-4A45-BC0F-9308BB211168}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ConsoleApplication1</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="源.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="源.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -1,2 +0,0 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
Debug|Win32|F:\VS test\ConsoleApplication1\|

@ -1,11 +0,0 @@
生成启动时间为 2018/4/23 12:50:28。
1>项目“F:\VS test\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj”在节点 2 上(Build 个目标)。
1>ClCompile:
D:\Microsoft Visual Studio 2015\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:prompt "源.cpp"
源.cpp
1>f:\vs test\consoleapplication1\consoleapplication1\源.cpp(16): fatal error C1083: 无法打开包括文件: “opencv.hpp”: No such file or directory
1>已完成生成项目“F:\VS test\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj”(Build 个目标)的操作 - 失败。
生成失败。
已用时间 00:00:03.57

@ -1,2 +0,0 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
Debug|x64|F:\VS test\ConsoleApplication1\|

@ -1,11 +0,0 @@
生成启动时间为 2018/5/19 20:50:17。
1>项目“F:\VS test\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj”在节点 2 上(Build 个目标)。
1>ClCompile:
D:\Microsoft Visual Studio 2015\VC\bin\x86_amd64\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc140.pdb" /Gd /TP /errorReport:prompt "源.cpp"
源.cpp
1>d:\microsoft visual studio 2015\vc\atlmfc\include\afx.h(24): fatal error C1189: #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
1>已完成生成项目“F:\VS test\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj”(Build 个目标)的操作 - 失败。
生成失败。
已用时间 00:00:02.72

@ -1,2 +0,0 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
Release|x64|F:\VS test\ConsoleApplication1\|

@ -1,18 +0,0 @@
生成启动时间为 2018/5/19 21:01:06。
1>项目“F:\VS test\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj”在节点 2 上(Build 个目标)。
1>ClCompile:
D:\Microsoft Visual Studio 2015\VC\bin\x86_amd64\CL.exe /c /Zi /nologo /W3 /WX- /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Release\\" /Fd"x64\Release\vc140.pdb" /Gd /TP /errorReport:prompt "源.cpp"
源.cpp
Link:
D:\Microsoft Visual Studio 2015\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"F:\VS test\ConsoleApplication1\x64\Release\ConsoleApplication1.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:D:\openCV3\opencv\build\x64\vc14\lib opencv_world330.lib opencv_world330d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug /PDB:"F:\VS test\ConsoleApplication1\x64\Release\ConsoleApplication1.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"F:\VS test\ConsoleApplication1\x64\Release\ConsoleApplication1.lib" /MACHINE:X64 "x64\Release\源.obj"
正在生成代码
8 of 415 functions ( 1.9%) were compiled, the rest were copied from previous compilation.
3 functions were new in current compilation
20 functions had inline decision re-evaluated but remain unchanged
已完成代码的生成
ConsoleApplication1.vcxproj -> F:\VS test\ConsoleApplication1\x64\Release\ConsoleApplication1.exe
1>已完成生成项目“F:\VS test\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj”(Build 个目标)的操作。
已成功生成。
已用时间 00:00:06.08

@ -1,247 +0,0 @@
#include <opencv2/opencv.hpp>
//#include <tchar.h>
//#include<afxdlgs.h>
using namespace std;
using namespace cv;
const static int SENSITIVITY_VALUE = 20;
// threshold()函数灵敏值设置为20
const static int BLUR_SIZE = 10; //blur模糊大小平滑图像以及增加跟踪物体大小
int theObject[2] = { 0,0 }; //只跟踪一个物体的位置,这里存放坐标
Rect objectBoundingRectangle = Rect(0, 0, 0, 0); // 对象的边界矩形用这个中心作为他的位置x,y,width,height)
string intToString(int number) { //数字转字符函数
std::stringstream ss;
ss << number;
return ss.str();
}
void searchForMovement(Mat thresholdImage, Mat &cameraFeed) {
bool objectDetected = false;
Mat temp;
thresholdImage.copyTo(temp); //将参数拷贝到临时变量temp
//存放findContours的输出
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
//使用openCV findContours函数找到过滤图像的轮廓
//findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE ); // retrieves all contours检索所有轮廓
findContours(temp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point());// retrieves external contours
//如果轮廓容器不是空的,说明我们找到了对象
if (contours.size()>0) objectDetected = true;
else objectDetected = false;
if (objectDetected) {
for (int i = 0; i < contours.size(); i ++) {
//绘制边界矩形
objectBoundingRectangle = boundingRect(contours[i]);
//找到中心点
int xpos = objectBoundingRectangle.x + objectBoundingRectangle.width / 2;
int ypos = objectBoundingRectangle.y + objectBoundingRectangle.height / 2;
theObject[0] = xpos, theObject[1] = ypos;
int x = theObject[0];
int y = theObject[1];
//绘制圆及十字线
circle(cameraFeed, Point(x, y), 20, Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x, y - 25), Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x, y + 25), Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x - 25, y), Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x + 25, y), Scalar(0, 255, 0), 2);
//打印坐标
putText(cameraFeed, "Coordinate (" + intToString(x) + "," + intToString(y) + ")", Point(x, y), 1, 1, Scalar(255, 0, 0), 2);
}
}
}
int main() {
//bool objectDetected = false; 或许添加功能
//调试跟踪两种模式可以通过按d或t切换
bool debugMode = false;
bool trackingEnabled = false;
//暂停和恢复
bool pause = false;
//为我们所要比较的两个帧创建图像容器
Mat frame1, frame2;
//使用absdiff()得到的他们的灰度图像
Mat grayImage1, grayImage2;
//得到差异图像
Mat differenceImage;
//在findContours()会用到的阈值差异图像
Mat thresholdImage;
//视频
VideoCapture capture;
//TCHAR ChosFile[] = _T("avi格式(*.avi)|*.avi|所有文件(*.*)|*.*||"); //过滤器
//打开文件对话框
//CFileDialog fileDlg(TRUE, _T("txt"), NULL, 0, ChosFile);
//保存路径
/*
CString filePathStr;
CFileDialog fileDlg(TRUE);
if (fileDlg.DoModal() == IDOK) {
filePathStr = fileDlg.GetPathName();
//CvCapture *capture = cvCreateFileCapture((CW2A)filePathStr);
}
else {
cout << "Open the File Error!\n";
}
//转换后的文件路径
char *lPath;
lPath = (char*)filePathStr.GetBuffer(filePathStr.GetLength());
*/
while (1) {
//循环视频,每当视频到达最后一帧重新开始捕捉
capture.open("bouncingBall.avi");
//capture.open(lPath);
//异常处理
if (!capture.isOpened()) {
cout << "ERROR ACQUIRING VIDEO FEED\n";
getchar();
return -1;
}
//检查视频是否到了最后一帧
int f = 0;
while (capture.get(CV_CAP_PROP_POS_FRAMES)<capture.get(CV_CAP_PROP_FRAME_COUNT) ) {
//读取第一帧
capture.read(frame1);
//第一帧时,前一帧用自身代替
if (f == 0){
frame2 = frame1.clone();
f = 1;
}
//将frame1转换为灰度图以进行帧差分
cvtColor(frame1, grayImage1, CV_BGR2GRAY);
//imshow("grayImage1",grayImage1);
//system("pause");
//将frame2转换为灰度以进行帧差分
cvtColor(frame2, grayImage2, CV_BGR2GRAY);
//保存当前帧,作为下一帧的前一帧使用
frame2 = frame1.clone();
absdiff(grayImage2, grayImage1, differenceImage); //两帧做差diff是差后图像
//imshow("diff", diff);//显示
//对差值图diff_thresh进行阈值化处理
threshold(differenceImage, thresholdImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY);
//imshow("diff_thresh", diff_thresh);
//如果是调试模式
if (debugMode ) {
//显示差异图像和阈值图像
imshow("differenceImage", differenceImage);
imshow("thresholdImage", thresholdImage);
}
else {
//如果不在调试模式下,则销毁窗口,以便我们不再看到它们
destroyWindow("differenceImage");
destroyWindow("thresholdImage");
}
//使用blur函数来平滑图像消除可能的噪音并增加我们跟踪的对象的大小。
//Mat blurImage;
blur(thresholdImage, thresholdImage, Size(BLUR_SIZE, BLUR_SIZE));
//将从模糊输出中获得的二进制图像再次阈值
threshold(thresholdImage, thresholdImage, SENSITIVITY_VALUE, 255, CV_THRESH_BINARY);
//如果是调试模式
if (debugMode) {
//在“模糊”之后显示阈值图像
imshow("thresholdImageAfterBlur", thresholdImage);
}
else {
destroyWindow("thresholdImageAfterBlur");
}
//如果启用了跟踪,则在阈值图像中搜索轮廓并在该帧上绘制轨迹
if (trackingEnabled ) {
searchForMovement(thresholdImage, frame1);//传的是引用
}
//显示帧
imshow("Frame1", frame1);
//检查是否有按钮被按下
//这10s的延迟对于程序的正确操作是必要的如果删除帧将没有足够的时间刷新并出现空白图像。
switch (waitKey(10)) { //4个按键 escd=debugt=trackingp=pause;
// ASCII码值
case 27: // esc 按下退出
return 0;
case 116: // t被按下切换到跟踪模式
trackingEnabled = !trackingEnabled;
if (trackingEnabled == 0) cout << "Tracking disabled." << endl;
else cout << "Tracking enabled." << endl;
break;
case 100: // d 被按下,切换到调试模式
debugMode = !debugMode; //更新标记
if (debugMode == 0) cout << "Debug mode disabled." << endl;
else cout << "Debug mode enabled." << endl;
break;
case 112: // p 暂停或恢复运行
pause = !pause;
if (pause == true) {
cout << "Paused, press 'p' again to resume" << endl;
while (pause == true) { //等待输入
// 如果是 p 则继续
if (waitKey(10) == 'p') {
//更新标记位
pause = !pause;
cout << "Code resumed." << endl;
}
}
}
}
}
//在重新循环前释放
capture.release();
}
return 0;
}

Binary file not shown.

@ -1,5 +1,5 @@
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
@ -7,7 +7,7 @@ const static int SENSITIVITY_VALUE = 20; // threshold()
const static int BLUR_SIZE = 10; //blur模糊大小平滑图像以及增加跟踪物体大小
int theObject[2] = { 0,0 }; //只跟踪一个物体的位置,这里存放坐标
int theObjectPos[2] = { 0,0 }; //只跟踪一个物体的位置,这里存放坐标
Rect objectBoundingRectangle = Rect(0, 0, 0, 0); // 对象的边界矩形用这个中心作为他的位置x,y,width,height)
@ -42,10 +42,11 @@ void searchForMovement(Mat thresholdImage, Mat &cameraFeed) {
//找到中心点
int xpos = objectBoundingRectangle.x + objectBoundingRectangle.width / 2;
int ypos = objectBoundingRectangle.y + objectBoundingRectangle.height / 2;
theObject[0] = xpos, theObject[1] = ypos;
theObjectPos[0] = xpos;
theObjectPos[1] = ypos;
int x = theObject[0];
int y = theObject[1];
int x = theObjectPos[0];
int y = theObjectPos[1];
//绘制圆及十字线
circle(cameraFeed, Point(x, y), 20, Scalar(0, 255, 0), 2);
line(cameraFeed, Point(x, y), Point(x, y - 25), Scalar(0, 255, 0), 2);
@ -87,26 +88,59 @@ int main() {
//视频
VideoCapture capture;
string filepath;
cout << "Please Enter the File Path: ";
cin >> filepath;
while (1) {
//循环视频,每当视频到达最后一帧重新开始捕捉
//capture.open("bouncingBall.avi");
//"bouncingBall.avi"
capture.open(filepath);
/*从文件打开部分待实现*/
//异常处理,打开失败
if (!capture.isOpened()) {
cout << "ERROR ACQUIRING VIDEO FEED\n";
cout << "ERROR! OPEN THE FILE FAILED\n";
getchar();
return -1;
}
//检查视频是否到了最后一帧
int first = 0;
while (capture.get(CV_CAP_PROP_POS_FRAMES)< capture.get(CV_CAP_PROP_FRAME_COUNT)-3) {
int first = 1;
while (capture.get(CV_CAP_PROP_POS_FRAMES)< capture.get(CV_CAP_PROP_FRAME_COUNT)) {
/*读取及灰度处理*/
//读取帧
if (first == 1) {
capture.read(frame1);
cvtColor(frame1, grayImage1, CV_BGR2GRAY);
capture.read(frame2);
cvtColor(frame2, grayImage2, CV_BGR2GRAY);
capture.read(frame3);
cvtColor(frame3, grayImage3, CV_BGR2GRAY);
first = 0;
}
else {
frame1 = frame2.clone();
grayImage1 = grayImage2.clone();
frame2 = frame3.clone();
grayImage2 = grayImage3.clone();
capture.read(frame3);
cvtColor(frame3, grayImage3, CV_BGR2GRAY);
}
/*
if (capture.read(frame1) == 0) {
capture.release();
break;
@ -114,34 +148,24 @@ int main() {
//将frame1转换为灰度以进行帧差分
cvtColor(frame1, grayImage1, CV_BGR2GRAY);
//waitKey(25);
//capture >> frame2;
//将frame2转换为灰度以进行帧差分
//capture.read(frame2);
if (capture.read(frame2) == 0) {
capture.release();
break;
};
}
//将frame2转换为灰度以进行帧差分
cvtColor(frame2, grayImage2, CV_BGR2GRAY);
//waitKey(25);
//capture >> frame3;
//将frame3转换为灰度以进行帧差分
if (capture.read(frame3) == 0) {
capture.release();
break;
};
cvtColor(frame3, grayImage3, CV_BGR2GRAY);
*/
//imshow("grayImage1",grayImage1);
//system("pause");
//对图像做简单平滑去噪处理
/*
Sobel(grayImage1, grayImage1, CV_8U, 1, 0, 3, 0.4, 128);
Sobel(grayImage2, grayImage2, CV_8U, 1, 0, 3, 0.4, 128);
Sobel(grayImage3, grayImage3, CV_8U, 1, 0, 3, 0.4, 128);
*/
/*图像做差后的二值化*/
@ -197,10 +221,11 @@ int main() {
//显示帧
imshow("Frame1", frame1);
//waitKey(30); //27或28时速度是流畅的
//检查是否有按钮被按下
//这10s的延迟对于程序的正确操作是必要的,如果删除,帧将没有足够的时间刷新并出现空白图像。
switch (waitKey(10)) { //4个按键 escd=debugt=trackingp=pause;
//延迟对于程序的正确操作是必要的,如果删除,帧将没有足够的时间刷新并出现空白图像。
switch (waitKey(33)) { //4个按键 escd=debugt=trackingp=pause;
// ASCII码值
case 27: // esc 按下退出
return 0;
@ -229,7 +254,7 @@ int main() {
while (pause == true) { //等待输入
// 如果是 p 则继续
if (waitKey(10) == 'p') {
if (waitKey(33) == 'p') {
//更新标记位
pause = !pause;
@ -244,6 +269,8 @@ int main() {
}
//在重新循环前释放
capture.release();
//break;
}
return 0;

@ -1,4 +1,4 @@
生成启动时间为 2018/5/29 17:24:56
生成启动时间为 2018/6/1 14:10:20
1>项目“F:\VS test\ThreeFrame\ThreeFrame\ThreeFrame.vcxproj”在节点 2 上(Build 个目标)。
1>ClCompile:
D:\Microsoft Visual Studio 2015\VC\bin\x86_amd64\CL.exe /c /Zi /nologo /W3 /WX- /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Release\\" /Fd"x64\Release\vc140.pdb" /Gd /TP /errorReport:prompt main.cpp
@ -6,13 +6,13 @@
Link:
D:\Microsoft Visual Studio 2015\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"F:\VS test\ThreeFrame\x64\Release\ThreeFrame.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:D:\openCV3\opencv\build\x64\vc14\lib opencv_world330.lib opencv_world330d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug /PDB:"F:\VS test\ThreeFrame\x64\Release\ThreeFrame.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"F:\VS test\ThreeFrame\x64\Release\ThreeFrame.lib" /MACHINE:X64 x64\Release\main.obj
正在生成代码
1 of 411 functions ( 0.2%) were compiled, the rest were copied from previous compilation.
1 of 438 functions ( 0.2%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
3 functions had inline decision re-evaluated but remain unchanged
0 functions had inline decision re-evaluated but remain unchanged
已完成代码的生成
ThreeFrame.vcxproj -> F:\VS test\ThreeFrame\x64\Release\ThreeFrame.exe
1>已完成生成项目“F:\VS test\ThreeFrame\ThreeFrame\ThreeFrame.vcxproj”(Build 个目标)的操作。
已成功生成。
已用时间 00:00:06.19
已用时间 00:00:09.56

Loading…
Cancel
Save