Skip to content

Commit

Permalink
Fixed Weird Frame Rate Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GlitcherOG committed Jul 25, 2022
1 parent 9e42f50 commit 526143f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
24 changes: 22 additions & 2 deletions CameraTest/Capture Display.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>BEAA974CE65F12677E83AFEDE29E3A6F37C226E5</ManifestCertificateThumbprint>
Expand Down Expand Up @@ -92,6 +92,27 @@
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accord, Version=3.8.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
<HintPath>..\packages\Accord.3.8.0\lib\net462\Accord.dll</HintPath>
Expand Down Expand Up @@ -343,7 +364,6 @@
<ItemGroup>
<Content Include="capture-icon-2.ico" />
<Content Include="capture-icon-2.jpg" />
<Content Include="License-LGPL.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.6.6.0\build\Fody.targets" Condition="Exists('..\packages\Fody.6.6.0\build\Fody.targets')" />
Expand Down
2 changes: 2 additions & 0 deletions CameraTest/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 22 additions & 18 deletions CameraTest/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ public void InitalizeCamera()
captureDevice.SignalToStop();
captureDevice.WaitForStop();
captureDevice.NewFrame -= CaptureDevice_NewFrame;
pictureBox1.Image = null;
pictureBox2.Image = null;
}
if(videoSourcePlayer1.VideoSource!=null)
{
Expand All @@ -174,7 +172,7 @@ public void InitalizeCamera()
pictureBox1.Visible = true;
pictureBox2.Visible = false;
}
else
else if(settings.RenderMode == 2)
{
pictureBox1.Visible = false;
pictureBox2.Visible = true;
Expand All @@ -193,7 +191,7 @@ public void InitalizeCamera()
captureDevice.Start();
for (int i = 0; i < captureDevice.VideoCapabilities.Length; i++)
{
RenderSizeComboBox.Items.Add(captureDevice.VideoCapabilities[i].FrameSize.Width.ToString() + " x " + captureDevice.VideoCapabilities[i].FrameSize.Height.ToString() + " @" + captureDevice.VideoCapabilities[i].MaximumFrameRate);
RenderSizeComboBox.Items.Add(captureDevice.VideoCapabilities[i].FrameSize.Width.ToString() + " x " + captureDevice.VideoCapabilities[i].FrameSize.Height.ToString() + " @" + captureDevice.VideoCapabilities[i].AverageFrameRate);
}
if (RenderSizeComboBox.Items.Count > 0)
{
Expand All @@ -205,7 +203,6 @@ public void InitalizeCamera()
{
RenderSizeComboBox.SelectedIndex = 0;
}
UpdateDisplayMode();
}
}
}
Expand All @@ -229,9 +226,10 @@ private void CaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
if (settings.RenderMode == 1)
{
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = bitmap;
}
else
else if(settings.RenderMode == 2)
{
pictureBox2.Image = (Bitmap)eventArgs.Frame.Clone();
}
Expand Down Expand Up @@ -326,20 +324,20 @@ private void Wave_DataAvailable(object sender, WaveInEventArgs e)
#region Display/Scale Options
private void RenderSizeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (captureDevice != null)
if (RenderSizeComboBox.SelectedIndex != -1)
{
var tempFPS = FPSCount;
FPSCount = false;
captureDevice.SignalToStop();
captureDevice.WaitForStop();
if (RenderSizeComboBox.SelectedIndex != -1)
if (captureDevice != null)
{
var tempFPS = FPSCount;
FPSCount = false;
captureDevice.SignalToStop();
captureDevice.WaitForStop();
captureDevice.VideoResolution = captureDevice.VideoCapabilities[RenderSizeComboBox.SelectedIndex];
UpdateDisplayMode();
captureDevice.Start();
FPSCount = tempFPS;
SetSettings();
}
UpdateDisplayMode();
captureDevice.Start();
FPSCount = tempFPS;
SetSettings();
}
}

Expand Down Expand Up @@ -477,12 +475,17 @@ void SizeObjectsScale()
videoSourcePlayer1.Location = new Point((ClientSize.Width - videoSourcePlayer1.ClientSize.Width) / 2, (ClientSize.Height - videoSourcePlayer1.ClientSize.Height) / 2);
}
change = true;
AutoSize = false;
pictureBox1.Location = videoSourcePlayer1.Location;
pictureBox1.Size = videoSourcePlayer1.Size;
pictureBox1.Dock = videoSourcePlayer1.Dock;
pictureBox2.Location = videoSourcePlayer1.Location;
pictureBox2.Size = videoSourcePlayer1.Size;
pictureBox2.Dock = videoSourcePlayer1.Dock;
if (DisplaySizeComboBox.SelectedIndex == 0)
{
AutoSize = true;
}
change = false;
}

Expand All @@ -496,7 +499,7 @@ private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(RenderModeComboBox.SelectedIndex!=-1)
{
settings.RenderMode = RenderModeComboBox.SelectedIndex;
settings.RenderMode = RenderModeComboBox.SelectedIndex;
SetSettings();
InitalizeCamera();
}
Expand Down Expand Up @@ -572,5 +575,6 @@ private void MainWindow_MouseEnter(object sender, EventArgs e)
UpdateDisplayMode();
}
}

}
}
6 changes: 6 additions & 0 deletions Capture Display.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Debug|x64.ActiveCfg = Debug|x64
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Debug|x64.Build.0 = Debug|x64
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Debug|x86.ActiveCfg = Debug|x86
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Debug|x86.Build.0 = Debug|x86
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Release|Any CPU.Build.0 = Release|Any CPU
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Release|x64.ActiveCfg = Release|x64
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Release|x64.Build.0 = Release|x64
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Release|x86.ActiveCfg = Release|x86
{396464B0-BAD1-424F-8326-4DB1348D2A19}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 526143f

Please sign in to comment.