Migrate PimpedWebcam

epvpn
Robert Jacob 2 years ago
parent 2854b68103
commit e727fb4379
  1. 98
      content/projekt/PimpedWebcam/index.md
  2. 0
      content/projekt/PimpedWebcam/webcam_blank.jpg
  3. 0
      content/projekt/PimpedWebcam/webcam_modified.jpg

@ -5,7 +5,7 @@ status: Aktiv
difficulty: einfach
time: ~1h
date: 2020-05-07
image: /images/PimpedWebcam/webcam_modified.jpg
image: webcam_modified.jpg
keywords: webcam, opencv, akvcam
---
@ -45,15 +45,17 @@ werden (ja, auch auf die Konsole ... ;). Damit stehen einfachen Manipulationen T
Hier mal die Resultate, zwecks Vergleich
vorher:
<img style="max-width: 300px"
alt="ohne"
src="/images/PimpedWebcam/webcam_blank.jpg"
src="webcam_blank.jpg"
/>
und nachher:
<img style="max-width: 300px"
alt="ohne"
src="/images/PimpedWebcam/webcam_modified.jpg"
src="webcam_modified.jpg"
/>
Hint: Die Kamera war wohl abgeklebt ...
@ -100,66 +102,66 @@ vorgesehen mit folgendem Ablauf:
virtcam.sh:
```Bash
echo "Installing video4 (output) / video5 (capture) virtual devices ..."
cd ~/akvcam/src
sudo modprobe videodev
sudo insmod akvcam.ko
echo "Starting 'stream modifier' application ..."
echo "Activating (cv) environment ..."
source ~/cv/bin/activate
cd ~/cv
ls /dev/video?
python3 funcam.py > /dev/video4 # video4 is output device -> video4 is capture
echo "Removing virtual (camera) devices ..."
sudo rmmod akvcam.ko
echo "Done."
```bash
echo "Installing video4 (output) / video5 (capture) virtual devices ..."
cd ~/akvcam/src
sudo modprobe videodev
sudo insmod akvcam.ko
echo "Starting 'stream modifier' application ..."
echo "Activating (cv) environment ..."
source ~/cv/bin/activate
cd ~/cv
ls /dev/video?
python3 funcam.py > /dev/video4 # video4 is output device -> video4 is capture
echo "Removing virtual (camera) devices ..."
sudo rmmod akvcam.ko
echo "Done."
```
Die eigentliche Action erfolgt im Python-Script ('funcam.py'):
```Python
import numpy as np
import datetime, time
import sys
import cv2
```python
import numpy as np
import datetime, time
import sys
import cv2
# Hint: print() to stderr (fh#2) as the actual video stream goes to stdout (fh#1)!
print("funcam started ...",file=sys.stderr)
# Hint: print() to stderr (fh#2) as the actual video stream goes to stdout (fh#1)!
print("funcam started ...",file=sys.stderr)
cap = cv2.VideoCapture(0) # TODO: You have to verify, if /dev/video0 is your actual webcam!
if not cap.isOpened(): # if not open already
cap.open() #make sure, we will have data
# Adjust channel resolution & use actual
cap.set(3, 640)
cap.set(4, 480)
cap = cv2.VideoCapture(0) # TODO: You have to verify, if /dev/video0 is your actual webcam!
if not cap.isOpened(): # if not open already
cap.open() #make sure, we will have data
# Adjust channel resolution & use actual
cap.set(3, 640)
cap.set(4, 480)
while(cap.isOpened()):
try:
ret, frame = cap.read()
if ret==True:
while(cap.isOpened()):
try:
ret, frame = cap.read()
if ret==True:
frame4 = cv2.cvtColor(frame.copy(),cv2.COLOR_BGRA2RGB) # Correct color space
frame4 = cv2.cvtColor(frame.copy(),cv2.COLOR_BGRA2RGB) # Correct color space
# Now: The fun stuff! -------------------------------------------------------------------------------------------
# Now: The fun stuff! -------------------------------------------------------------------------------------------
# ... <your job in here, use cv2.line/cv2.rectangle etc. freely but be careful w/ time consuming operations!> ...
# ... <your job in here, use cv2.line/cv2.rectangle etc. freely but be careful w/ time consuming operations!> ...
# As a sample, we display the current time
t = time.strftime("%H:%M:%S", time.localtime())
cv2.putText(frame4, t, (505,472), (cv2.FONT_HERSHEY_DUPLEX), 1.4, (0, 0, 0), 4, cv2.LINE_AA)
# As a sample, we display the current time
t = time.strftime("%H:%M:%S", time.localtime())
cv2.putText(frame4, t, (505,472), (cv2.FONT_HERSHEY_DUPLEX), 1.4, (0, 0, 0), 4, cv2.LINE_AA)
# End of fun stuff! ---------------------------------------------------------------------------------------------
# End of fun stuff! ---------------------------------------------------------------------------------------------
# Write raw output (pipe/redirect to video device externally!)
sys.stdout.buffer.write(frame4.tobytes())
else:
break
except:
# Write raw output (pipe/redirect to video device externally!)
sys.stdout.buffer.write(frame4.tobytes())
else:
break
except:
break
cap.release()
print("\nfuncam terminated.",file=sys.stderr)
cap.release()
print("\nfuncam terminated.",file=sys.stderr)
```
## Arbeitsablauf

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Loading…
Cancel
Save