utils: raspberrypi: ctt: Improve the Macbeth Chart search reliability

Previously the code would brighten up images in case the Macbeth Chart
is slightly dark, and also zoom in on sections of it to look for
charts occupying less of the field of view. But it would not do both
together.

This change makes the search for smaller charts also repeat that
search for the brightened up images that it made earlier, thereby
increasing the chances of success for non-optimal tuning images.

There are also a couple of very small drive-by typo fixes.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
David Plowman 2023-12-01 11:07:53 +00:00 committed by Kieran Bingham
parent cfb4bee74b
commit 66479605ba

View file

@ -57,6 +57,10 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
""" """
cor, mac, coords, msg = get_macbeth_chart(img, ref_data) cor, mac, coords, msg = get_macbeth_chart(img, ref_data)
# Keep a list that will include this and any brightened up versions of
# the image for reuse.
all_images = [img]
""" """
following bits of code tries to fix common problems with simple following bits of code tries to fix common problems with simple
techniques. techniques.
@ -71,6 +75,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
if cor < 0.75: if cor < 0.75:
a = 2 a = 2
img_br = cv2.convertScaleAbs(img, alpha=a, beta=0) img_br = cv2.convertScaleAbs(img, alpha=a, beta=0)
all_images.append(img_br)
cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data) cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data)
if cor_b > cor: if cor_b > cor:
cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b
@ -81,6 +86,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
if cor < 0.75: if cor < 0.75:
a = 4 a = 4
img_br = cv2.convertScaleAbs(img, alpha=a, beta=0) img_br = cv2.convertScaleAbs(img, alpha=a, beta=0)
all_images.append(img_br)
cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data) cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data)
if cor_b > cor: if cor_b > cor:
cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b
@ -128,11 +134,14 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
h_inc = int(h/6) h_inc = int(h/6)
""" """
for each subselection, look for a macbeth chart for each subselection, look for a macbeth chart
loop over this and any brightened up images that we made to increase the
likelihood of success
""" """
for img_br in all_images:
for i in range(3): for i in range(3):
for j in range(3): for j in range(3):
w_s, h_s = i*w_inc, j*h_inc w_s, h_s = i*w_inc, j*h_inc
img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] img_sel = img_br[w_s:w_s+w_sel, h_s:h_s+h_sel]
cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data)
""" """
if the correlation is better than the best then record the if the correlation is better than the best then record the
@ -157,10 +166,12 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
h_sel = int(h/2) h_sel = int(h/2)
w_inc = int(w/8) w_inc = int(w/8)
h_inc = int(h/8) h_inc = int(h/8)
# Again, loop over any brightened up images as well
for img_br in all_images:
for i in range(5): for i in range(5):
for j in range(5): for j in range(5):
w_s, h_s = i*w_inc, j*h_inc w_s, h_s = i*w_inc, j*h_inc
img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] img_sel = img_br[w_s:w_s+w_sel, h_s:h_s+h_sel]
cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data)
if cor_ij > cor: if cor_ij > cor:
cor = cor_ij cor = cor_ij
@ -238,7 +249,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
print error or success message print error or success message
""" """
print(msg) print(msg)
Cam.log += '\n' + msg Cam.log += '\n' + str(msg)
if msg == success_msg: if msg == success_msg:
coords_fit = coords coords_fit = coords
Cam.log += '\nMacbeth chart vertices:\n' Cam.log += '\nMacbeth chart vertices:\n'
@ -606,7 +617,7 @@ def get_macbeth_chart(img, ref_data):
'\nNot enough squares found' '\nNot enough squares found'
'\nPossible problems:\n' '\nPossible problems:\n'
'- Macbeth chart is occluded\n' '- Macbeth chart is occluded\n'
'- Macbeth chart is too dark of bright\n' '- Macbeth chart is too dark or bright\n'
) )
ref_cents = np.array(ref_cents) ref_cents = np.array(ref_cents)