Hi, I am fairly new to this forum and building my first complete setup.
My complements to the team that made Hyperion/Hyperbian!
I can't tell you how long I wanted to have 'ambilight', but without having to buy a Philips TV.
But, back on the topic: I found a way to find the optimal setting of brightness/contrast/saturation/hue for any grabber available by exploiting a python script of a guy naming himself ciko. Great work man!
You can find it here, but it won't work out of the box since skimage changes and also I had to alter the videframe buffer size.
First you need to installing below packages:
sudo apt-get update (optional, but was needed when I tried installing below)
sudo apt-get install python3-skimage
sudo apt-get install python3-opencv
from skimage.metrics import structural_similarity
import cv2
import random, os, time
original = cv2.imread("artificial.png")
# open the video device
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FOURCC , cv2.VideoWriter_fourcc(*"YUYV")) # also possible to select MJPEG instead of YUYV
cap.set(3, 1920)
cap.set(4, 1080)
cap.set(cv2.CAP_PROP_BUFFERSIZE,1) # needed else grabbing previous images with other/previous settings
# initialize video capture and set all possible parameters
combinations = []
while True:
brightness = random.randint(-30, 30)
contrast = random.randint(120, 170)
saturation = random.randint(120, 140)
hue = random.randint(-10, 10)
print(f"Testing brightness:{brightness} contrast:{contrast} saturation:{saturation} hue:{hue}")
os.system(f"v4l2-ctl -d /dev/video0 --set-ctrl=brightness={brightness}")
os.system(f"v4l2-ctl -d /dev/video0 --set-ctrl=contrast={contrast}")
os.system(f"v4l2-ctl -d /dev/video0 --set-ctrl=saturation={saturation}")
os.system(f"v4l2-ctl -d /dev/video0 --set-ctrl=hue={hue}")
time.sleep(5) # Wait for the capture card to adopt
ret, captured = cap.read()
# do it twice to match the buffersize of 1, which should make sure we have a fresh frame with above settings applied
ret, captured = cap.read()
score = structural_similarity(original, captured, multichannel=True)
combinations.append([brightness, contrast, saturation, hue, score])
for r in sorted(combinations, key=lambda x: x[4], reverse=True)[:10]:
print(r)
cap.release()
Display More
Next to this you need offer the grabber a 1920x1080 test image via its HMDI connection (lots of colors!).
The same image must be available for the script itself (named 'artificial.png' in above python script).
The script can now be executed by:
python <name of the file of the script>
The script will compare the image grabs for a random set values for brightness, contrast, saturation and hue.
The top 10 will be build up and updated as you keep running the script (30 minutes / 1 hour, it just keeps narrows the range for the optimal settings).
I ordered 6 'different' USB grabbers from Ali (which proved to all have been based on the MacroSilicon chip) and ran this script.
An example top 10 (from best to worst, up to down):
[brightness, contrast, saturation, hue, similarity score by SK Image library]
[0, 130, 128, 1, 0.9790735862137337]
[0, 130, 128, 1, 0.9790735862137337]
[0, 130, 128, 1, 0.9790735862137337]
[0, 131, 128, 1, 0.9785554986591819]
[0, 131, 128, 2, 0.9779354215036543]
[0, 129, 128, 3, 0.977378649197668]
[0, 129, 128, 3, 0.977378649197668]
[0, 129, 131, 3, 0.9773188600386898]
[0, 129, 131, 3, 0.9773188600386898]
[0, 131, 130, 2, 0.9772894482817124]
[0, 129, 130, 2, 0.977280399322154]
I tested all 6 USB grabbers I have and all ended up with above values for optimal similarity of images grabbed and offered via HDMI.
brightness 0x00980900 (int) : min=-128 max=127 step=1 default=-11 value=0
contrast 0x00980901 (int) : min=0 max=255 step=1 default=148 value=130
saturation 0x00980902 (int) : min=0 max=255 step=1 default=180 value=128
hue 0x00980903 (int) : min=-128 max=127 step=1 default=0 value=1
It is remarkable that the defaults found in all 6 grabbers are very different to optimal...
Maybe optimizing here isn't helping much in for the end result, since you may compensate for the unneeded grabber error by calibrating the leds vs the output of the TV. Still, it was a cool experiment and fun to do and there is less error now to be corrected!
Next step is calibrating the colors of the LEDs vs. the output of the TV... with a camera... semi-automatic would be nice!