Skip to content

Commit 546fb03

Browse files
committed
exposure
1 parent 829ccd2 commit 546fb03

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

conftest.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
import cv2
55
import subprocess
6+
import numpy as np
67
from pathlib import Path
78

89

@@ -43,18 +44,42 @@ def pytest_collection_modifyitems(config, items):
4344
item.add_marker(pytest.mark.skip(reason="Not for selected params"))
4445

4546

47+
def bsp_image_correction(image):
48+
pts_src = np.float32([
49+
[160, 80], # top-left
50+
[1044, 87], # top-right
51+
[279, 720], # bottom-left
52+
[913, 718] # bottom-right
53+
])
54+
55+
width, height = 1000, 884
56+
pts_dst = np.float32([
57+
[0, 0],
58+
[width, 0],
59+
[0, height],
60+
[width, height]
61+
])
62+
63+
matrix = cv2.getPerspectiveTransform(pts_src, pts_dst)
64+
warped = cv2.warpPerspective(image, matrix, (width, height))
65+
return warped
66+
67+
4668
def bsp_capture_image(image_path, board):
4769
# Enable auto-focus
48-
subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=focus_auto=1"])
70+
# subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=focus_auto=1"])
71+
# Manual focus
72+
subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=focus_auto=0"])
73+
subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=focus_absolute=20"])
4974
# Manual exposition
5075
subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=exposure_auto=1"])
51-
subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=exposure_absolute=100"])
76+
subprocess.run(["v4l2-ctl", "-d", "/dev/video0", "--set-ctrl=exposure_absolute=1"])
5277

5378
# Return video from the first webcam on your computer.
5479
cap = cv2.VideoCapture(0)
5580
# Set FullHD resolution (1920x1080)
56-
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
57-
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
81+
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
82+
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
5883

5984
# TODO: Camera calibration
6085

@@ -68,6 +93,9 @@ def bsp_capture_image(image_path, board):
6893
# TODO: Change size image
6994
# TODO: Crop image for {board}
7095

96+
# correction image perspective and crop
97+
frame = bsp_image_correction(frame)
98+
7199
# Save image
72100
cv2.imwrite(image_path, frame)
73101
print(f"Image saved {image_path}")

0 commit comments

Comments
 (0)