Skip to content
Snippets Groups Projects
Commit 2ebcbee7 authored by Petteri Laitinen's avatar Petteri Laitinen
Browse files

testejä eriytetty pois pääkoodista.

Roskis-kansio poistettu.
parent 2eba3aaf
Branches
No related tags found
No related merge requests found
Pipeline #24984 failed
...@@ -5,9 +5,15 @@ before_script: ...@@ -5,9 +5,15 @@ before_script:
- pip install -r requirements.txt - pip install -r requirements.txt
stages: stages:
- kehitystesti - perustesti
- toinentesti
kokeilutesti: kokeilutesti:
stage: kehitystesti stage: perustesti
script: script:
- python bayesian_adapted_gmm_for_background_extraction.py - python bayesian_adapted_gmm_for_background_extraction.py
laajatesti:
stage: toinentesti
script:
- python test.py
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
import numpy as np
import cv2
class GMM():
def __init__(self,prior,windowlength,gaussians):
"""
Initialize the Gaussian mixture model.
Parameters
----------
prior : float
a priori probability of background.
windowlength : int
how many frames are used in te start of the video to calculate gaussians
gaussians : int
number of gaussians used
"""
self.prior = prior
self.windowlength=windowlength
self.gaussians=gaussians
self.weights=np.ones(gaussians)/gaussians
self.averages=np.ones(gaussians)
self.variances=np.ones(gaussians)
class Gaussian():
def __init__(self, numberofgaussians):
"""
Initialize
"""
pass
print(GMM(0.1,100,3).weights)

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29926.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bayesian_adapted_gmm_for_background_extraction", "bayesian_adapted_gmm_for_background_extraction.vcxproj", "{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}"
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
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Debug|x64.ActiveCfg = Debug|x64
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Debug|x64.Build.0 = Debug|x64
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Debug|x86.ActiveCfg = Debug|Win32
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Debug|x86.Build.0 = Debug|Win32
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Release|x64.ActiveCfg = Release|x64
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Release|x64.Build.0 = Release|x64
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Release|x86.ActiveCfg = Release|Win32
{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D30A519-03F1-480A-8D98-D5CE3D672110}
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{10186FC0-842B-40BB-AA5D-7F5B58EA0A8B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
</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)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include=".gitlab-ci.yml" />
<None Include="camera_cali.py" />
<None Include="ci_test_program.py" />
<None Include="class4.py" />
<None Include="GMM.py" />
<None Include="main_program.py" />
<None Include="pikseli.py" />
<None Include="README.md" />
<None Include="Sovellettu GMM-malli LAitinen.pptx" />
<None Include="testi.py" />
</ItemGroup>
<ItemGroup>
<Media Include="test_video_1.MP4" />
<Media Include="test_video_2.MP4" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<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</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="camera_cali.py" />
<None Include="ci_test_program.py" />
<None Include="class4.py" />
<None Include="GMM.py" />
<None Include="main_program.py" />
<None Include="pikseli.py" />
<None Include="testi.py" />
<None Include="README.md" />
<None Include="Sovellettu GMM-malli LAitinen.pptx" />
<None Include=".gitlab-ci.yml" />
</ItemGroup>
<ItemGroup>
<Media Include="test_video_1.MP4" />
<Media Include="test_video_2.MP4" />
</ItemGroup>
</Project>
\ No newline at end of file
## First some code to test
import os
import cv2
import numpy as np
print(os.getcwd())
#execfile('ci_test_program.py')
## Then the actual class
class BackgroundSubtractorBayes():
def __init__(self,prior,windowlength,gaussians):
"""
Initialize the Gaussian mixture model.
Parameters
----------
prior : float
a priori probability of background.
windowlength : int
how many frames are used in te start of the video to calculate gaussians
gaussians : int
number of gaussians used
"""
self.prior = prior
self.windowlength=windowlength
self.gaussians=gaussians
self.weights=np.ones(gaussians)/gaussians
self.averages=np.ones(gaussians)
self.variances=np.ones(gaussians)
self.core=cv2.createBackgroundSubtractorMOG2()
self.framelista=[]
self.generation=0
def apply(self,InputFrame,OtherIndex):
if self.prior<1 and self.prior>0.6:
## The adapted algorithm comes here
#OutputFrame=InputFrame
OutputFrame = self.core.apply(InputFrame)
framelista.append(freimi(OtherIndex,InputFrame))
temporarylista=[]
if generation>1:
for i in range(0,2,1):
temporarylista.append(self.framelista[generation-i].frame)
median = np.median(self.temporarylista, axis=0).astype(dtype=np.uint8)
generation=generation+1
OutputFrame=median
else:
## if the probabilities for both background and foregraound are around 50%,
## use the normal Mixture of Gaussians.
# This will give gray frames only because subtractor is initialized for every frame
#backSub = cv2.createBackgroundSubtractorMOG2()
#OutputFrame=backSub.apply(InputFrame)
OutputFrame = self.core.apply(InputFrame)
#framelista.append([self.generation, freimi(OtherIndex,InputFrame)])
#median = np.median(frames, axis=0).astype(dtype=np.uint8)
return OutputFrame
class freimi():
def __init__(self,numero,frame):
"""
Initialize the Gaussian mixture model.
Parameters
----------
numero : int
frame number
frame : NEEDS TO BE DEFINED matrix with integer values 0...255 ?
the actual frame
frb : int
"""
self.numero=numero
self.frame=frame
koeBayes=BackgroundSubtractorBayes(0.61,10,3)
cap = cv2.VideoCapture('test_video_1.mp4')
frame_idx = cap.get(cv2.CAP_PROP_FRAME_COUNT) - 1
takaperinlista=[]
etuperinlista=[]
# voitaneen poistaa?
#AltSub = cv2.createBackgroundSubtractorMOG2()
if 1>0:
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#g2= BackgroundSubtractorBayes.apply(gray,0.7)
#g3=AltSub.apply(gray)
#g4=koeBayes.core.apply(gray)
g5=koeBayes.apply(gray)
etuperinlista.append(freimi('etuperin',int(cap.get(cv2.CAP_PROP_POS_FRAMES)),g5))
cv2.imshow('frame',g5)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
while cap.isOpened() and frame_idx >= 0:
# Set the current frame position to start:
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_idx)
ret, frame = cap.read()
if ret is True:
# Display the frame:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#g2= BackgroundSubtractorBayes.apply(gray,0.7)
#g3=AltSub.apply(gray)
g4=koeBayes.core.apply(gray)
g5=koeBayes.apply(gray)
cv2.imshow('frame',g5)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Reduce the index to read next frame:
frame_idx = frame_idx - 1
#print("Next index: '{}'".format(frame_idx))
cap.release()
cv2.destroyAllWindows()
print('Terve')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment