second commit
This commit is contained in:
parent
04852ce382
commit
fada1f1b85
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/WebcamTest.iml" filepath="$PROJECT_DIR$/.idea/WebcamTest.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import cv2
|
||||
|
||||
# Lade das erste Frame und bestimme seine Größe
|
||||
cap = cv2.VideoCapture(0)
|
||||
ret, frame = cap.read()
|
||||
height, width, channels = frame.shape
|
||||
|
||||
# Definiere einen Bereich, der ausgeschlossen werden soll
|
||||
exclude_area = [[0, 0], [0, 100], [width, 100], [width, 0]]
|
||||
|
||||
# Erstelle eine Maske
|
||||
mask = np.zeros((height, width), np.uint8)
|
||||
pts = np.array([exclude_area], np.int32)
|
||||
cv2.fillPoly(mask, pts, 255)
|
||||
|
||||
# Initialisiere den Hintergrundsubtraktor
|
||||
fgbg = cv2.createBackgroundSubtractorMOG2()
|
||||
|
||||
while True:
|
||||
# Lese das nächste Frame
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
# Wende die Maske auf das Frame an
|
||||
masked_frame = cv2.bitwise_and(frame, frame, mask=mask)
|
||||
|
||||
# Subtrahiere das Hintergrund-Modell von dem aktuellen Frame
|
||||
fgmask = fgbg.apply(masked_frame)
|
||||
|
||||
# Wende eine Schwellenwertbildung auf das Differenzbild an
|
||||
thresh = cv2.threshold(fgmask, 127, 255, cv2.THRESH_BINARY)[1]
|
||||
|
||||
# Zeige das Ergebnis an
|
||||
cv2.imshow('frame', thresh)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
Loading…
Reference in New Issue