set_exposure_target test (#20318)
* build * remove junk * clean up * clean up rebase * new patterns * add gts * add to jenkis * this more useful * typo * test only * Update Jenkinsfile * test flag * remove from jenkins * these should all just be common:wq * oops * unigt * add to unit tests? * build all is fine Co-authored-by: Comma Device <device@comma.ai>pull/20337/head
parent
ad123714ba
commit
65bb979c34
12 changed files with 150 additions and 108 deletions
@ -0,0 +1,70 @@ |
|||||||
|
// unittest for set_exposure_target
|
||||||
|
|
||||||
|
#include <assert.h> |
||||||
|
#include <cstring> |
||||||
|
#include <cmath> |
||||||
|
|
||||||
|
#include "selfdrive/camerad/cameras/camera_common.h" |
||||||
|
#include "selfdrive/camerad/test/ae_gray_test.h" |
||||||
|
|
||||||
|
void camera_autoexposure(CameraState *s, float grey_frac) {} |
||||||
|
|
||||||
|
int main() { |
||||||
|
// set up fake camerabuf
|
||||||
|
CameraBuf cb = {}; |
||||||
|
VisionBuf vb = {}; |
||||||
|
uint8_t * fb_y = new uint8_t[W*H]; |
||||||
|
vb.y = fb_y; |
||||||
|
cb.cur_yuv_buf = &vb; |
||||||
|
cb.rgb_width = W; |
||||||
|
cb.rgb_height = H; |
||||||
|
|
||||||
|
printf("AE test patterns %dx%d\n", cb.rgb_width, cb.rgb_height); |
||||||
|
|
||||||
|
// mix of 5 tones
|
||||||
|
uint8_t l[5] = {0, 24, 48, 96, 235}; // 235 is yuv max
|
||||||
|
|
||||||
|
bool passed = true; |
||||||
|
float rtol = 0.05; |
||||||
|
// generate pattern and calculate EV
|
||||||
|
int cnt = 0; |
||||||
|
for (int is_qcom2=0; is_qcom2<2; is_qcom2++) { |
||||||
|
for (int g=0; g<GAIN_SPLITS; g++) { |
||||||
|
for (int i_0=0; i_0<TONE_SPLITS; i_0++) { |
||||||
|
for (int i_1=0; i_1<TONE_SPLITS; i_1++) { |
||||||
|
for (int i_2=0; i_2<TONE_SPLITS; i_2++) { |
||||||
|
for (int i_3=0; i_3<TONE_SPLITS; i_3++) { |
||||||
|
int h_0 = i_0 * H / TONE_SPLITS; |
||||||
|
int h_1 = i_1 * (H - h_0) / TONE_SPLITS; |
||||||
|
int h_2 = i_2 * (H - h_0 - h_1) / TONE_SPLITS; |
||||||
|
int h_3 = i_3 * (H - h_0 - h_1 - h_2) / TONE_SPLITS; |
||||||
|
int h_4 = H - h_0 - h_1 - h_2 - h_3; |
||||||
|
memset(&fb_y[0], l[0], h_0*W); |
||||||
|
memset(&fb_y[h_0*W], l[1], h_1*W); |
||||||
|
memset(&fb_y[h_0*W+h_1*W], l[2], h_2*W); |
||||||
|
memset(&fb_y[h_0*W+h_1*W+h_2*W], l[3], h_3*W); |
||||||
|
memset(&fb_y[h_0*W+h_1*W+h_2*W+h_3*W], l[4], h_4*W); |
||||||
|
float ev = set_exposure_target((const CameraBuf*) &cb, 0, W-1, 1, 0, H-1, 1, g*10, (bool)is_qcom2, (bool)is_qcom2); |
||||||
|
// printf("%d/%d/%d/%d/%d ev is %f\n", h_0, h_1, h_2, h_3, h_4, ev);
|
||||||
|
// printf("%f\n", ev);
|
||||||
|
|
||||||
|
// compare to gt
|
||||||
|
float evgt = gts[cnt]; |
||||||
|
if (fabs(ev - evgt) > rtol*evgt) { |
||||||
|
passed = false; |
||||||
|
} |
||||||
|
|
||||||
|
// report
|
||||||
|
printf("%d/%d/%d/%d/%d/%d/%d: ev %f, gt %f, err %f\n", is_qcom2, g*10, h_0, h_1, h_2, h_3, h_4, ev, evgt, fabs(ev - evgt) / (evgt != 0 ? evgt : 0.00001f)); |
||||||
|
cnt++; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
assert(passed); |
||||||
|
|
||||||
|
delete[] fb_y; |
||||||
|
return 0; |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#define W 240 |
||||||
|
#define H 160 |
||||||
|
|
||||||
|
#define TONE_SPLITS 3 |
||||||
|
#define GAIN_SPLITS 2 |
||||||
|
|
||||||
|
float gts[2*TONE_SPLITS*TONE_SPLITS*TONE_SPLITS*TONE_SPLITS*GAIN_SPLITS] = { |
||||||
|
0.917969,0.917969,0.375000,0.917969,0.375000,0.375000,0.187500,0.187500,0.187500,0.917969, |
||||||
|
0.375000,0.375000,0.187500,0.187500,0.187500,0.187500,0.187500,0.187500,0.093750,0.093750, |
||||||
|
0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.917969,0.375000,0.375000, |
||||||
|
0.187500,0.187500,0.187500,0.187500,0.187500,0.187500,0.093750,0.093750,0.093750,0.093750, |
||||||
|
0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750, |
||||||
|
0.093750,0.093750,0.093750,0.093750,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, |
||||||
|
0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, |
||||||
|
0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, |
||||||
|
0.000000,0.917969,0.917969,0.375000,0.917969,0.375000,0.375000,0.187500,0.187500,0.187500, |
||||||
|
0.917969,0.375000,0.375000,0.187500,0.187500,0.187500,0.187500,0.187500,0.187500,0.093750, |
||||||
|
0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.917969,0.375000, |
||||||
|
0.375000,0.187500,0.187500,0.187500,0.187500,0.187500,0.187500,0.093750,0.093750,0.093750, |
||||||
|
0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750,0.093750, |
||||||
|
0.093750,0.093750,0.093750,0.093750,0.093750,0.000000,0.000000,0.000000,0.000000,0.000000, |
||||||
|
0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, |
||||||
|
0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, |
||||||
|
0.000000,0.000000,4.527344,3.324219,0.457031,4.421875,3.265625,0.453125,4.324219,3.167969, |
||||||
|
0.449219,4.421875,3.265625,0.453125,4.234375,3.113281,0.449219,3.980469,2.929688,0.441406, |
||||||
|
4.324219,3.167969,0.449219,3.980469,2.929688,0.441406,3.558594,0.433594,0.433594,4.421875, |
||||||
|
3.265625,0.453125,4.234375,3.113281,0.449219,3.980469,2.929688,0.441406,4.234375,3.113281, |
||||||
|
0.449219,3.929688,2.902344,0.441406,3.484375,0.429688,0.429688,3.980469,2.929688,0.441406, |
||||||
|
3.484375,0.429688,0.429688,2.871094,0.417969,0.417969,4.324219,3.167969,0.449219,3.980469, |
||||||
|
2.929688,0.441406,3.558594,0.433594,0.433594,3.980469,2.929688,0.441406,3.484375,0.429688, |
||||||
|
0.429688,2.871094,0.417969,0.417969,3.558594,0.433594,0.433594,2.871094,0.417969,0.417969, |
||||||
|
0.308594,0.308594,0.308594,4.253906,3.140625,0.574219,4.156250,3.085938,0.566406,4.066406, |
||||||
|
2.996094,0.562500,4.156250,3.085938,0.566406,3.984375,2.945312,0.554688,3.750000,2.777344, |
||||||
|
0.542969,4.066406,2.996094,0.562500,3.750000,2.777344,0.542969,3.359375,0.519531,0.519531, |
||||||
|
4.156250,3.085938,0.566406,3.984375,2.945312,0.554688,3.750000,2.777344,0.542969,3.984375, |
||||||
|
2.945312,0.554688,3.699219,2.753906,0.539062,3.289062,0.515625,0.515625,3.750000,2.777344, |
||||||
|
0.542969,3.289062,0.515625,0.515625,2.722656,0.480469,0.480469,4.066406,2.996094,0.562500, |
||||||
|
3.750000,2.777344,0.542969,3.359375,0.519531,0.519531,3.750000,2.777344,0.542969,3.289062, |
||||||
|
0.515625,0.515625,2.722656,0.480469,0.480469,3.359375,0.519531,0.519531,2.722656,0.480469, |
||||||
|
0.480469,0.328125,0.328125,0.328125, |
||||||
|
}; |
@ -1,48 +0,0 @@ |
|||||||
# flake8: noqa |
|
||||||
# pylint: disable=W |
|
||||||
|
|
||||||
#!/usr/bin/env python |
|
||||||
import numpy as np |
|
||||||
import cv2 |
|
||||||
from time import time, sleep |
|
||||||
|
|
||||||
H, W = (604*2//6, 964*2//6) |
|
||||||
# H, W = (604, 964) |
|
||||||
|
|
||||||
cam_bufs = np.zeros((3,H,W,3), dtype=np.uint8) |
|
||||||
hist_bufs = np.zeros((3,H,200,3), dtype=np.uint8) |
|
||||||
|
|
||||||
if __name__ == '__main__': |
|
||||||
import zmq |
|
||||||
context = zmq.Context() |
|
||||||
socket = context.socket(zmq.PULL) |
|
||||||
socket.bind("tcp://192.168.3.4:7768") |
|
||||||
while True: |
|
||||||
try: |
|
||||||
message = socket.recv() |
|
||||||
except Exception as ex: |
|
||||||
print(ex) |
|
||||||
message = b"123" |
|
||||||
|
|
||||||
dat = np.frombuffer(message, dtype=np.uint8) |
|
||||||
cam_id = (dat[0] + 1) % 3 |
|
||||||
# import pdb; pdb.set_trace() |
|
||||||
b = dat[::3].reshape(H, W) |
|
||||||
g = dat[1::3].reshape(H, W) |
|
||||||
r = dat[2::3].reshape(H, W) |
|
||||||
cam_bufs[cam_id] = cv2.merge((r, g, b)) |
|
||||||
cam_bufs[cam_id]= cv2.cvtColor(cam_bufs[cam_id], cv2.COLOR_RGB2BGR) |
|
||||||
|
|
||||||
hist = cv2.calcHist([cv2.cvtColor(cam_bufs[cam_id], cv2.COLOR_BGR2GRAY)],[0],None,[32],[0,256]) |
|
||||||
hist = (H*hist/hist.max()).astype(np.uint8) |
|
||||||
hist_bufs[cam_id] = 0 |
|
||||||
for i,bb in enumerate(hist): |
|
||||||
hist_bufs[cam_id, H-bb[0]:,i*(200//32):(i+1)*(200//32), :] = (222,222,222) |
|
||||||
|
|
||||||
out = cam_bufs.reshape((3*H,W,3)) |
|
||||||
hist_bufs_out = hist_bufs.reshape((3*H,200,3)) |
|
||||||
out = np.hstack([out, hist_bufs_out]) |
|
||||||
cv2.imshow('RGB', out) |
|
||||||
cv2.waitKey(55) |
|
||||||
#dat.tofile('/tmp/c3rgb.img') |
|
||||||
#cv2.imwrite('/tmp/c3rgb.png', out) |
|
@ -1,34 +0,0 @@ |
|||||||
# flake8: noqa |
|
||||||
# pylint: disable=W |
|
||||||
|
|
||||||
#!/usr/bin/env python |
|
||||||
import numpy as np |
|
||||||
import cv2 |
|
||||||
from time import time, sleep |
|
||||||
|
|
||||||
H, W = (256, 512) |
|
||||||
|
|
||||||
if __name__ == '__main__': |
|
||||||
import zmq |
|
||||||
context = zmq.Context() |
|
||||||
socket = context.socket(zmq.PULL) |
|
||||||
socket.bind("tcp://192.168.3.4:7769") |
|
||||||
while True: |
|
||||||
try: |
|
||||||
message = socket.recv() |
|
||||||
except Exception as ex: |
|
||||||
print(ex) |
|
||||||
message = b"123" |
|
||||||
|
|
||||||
dat = np.frombuffer(message, dtype=np.float32) |
|
||||||
mc = (dat.reshape(H//2, W//2)).astype(np.uint8) |
|
||||||
|
|
||||||
hist = cv2.calcHist([mc],[0],None,[32],[0,256]) |
|
||||||
hist = (H*hist/hist.max()).astype(np.uint8) |
|
||||||
himg = np.zeros((H//2, W//2), dtype=np.uint8) |
|
||||||
for i,b in enumerate(hist): |
|
||||||
himg[H//2-b[0]:,i*(W//2//32):(i+1)*(W//2//32)] = 222 |
|
||||||
|
|
||||||
cv2.imshow('model fov', np.hstack([mc, himg])) |
|
||||||
cv2.waitKey(20) |
|
||||||
dat.tofile('/tmp/c3yuv.img') |
|
Loading…
Reference in new issue