From be65da18bb04ace88085470d4afc60dc298664bb Mon Sep 17 00:00:00 2001 From: dronus <paul.geisler@web.de> Date: Sun, 22 Aug 2021 20:45:05 +0200 Subject: [PATCH] output roughness, more parameters configurable (cropping etc.) --- conf.json | 6 +++++- linescan.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/conf.json b/conf.json index 2872a9a..1b19946 100644 --- a/conf.json +++ b/conf.json @@ -1,6 +1,8 @@ { "camera_warmup_time": 2.5, "resolution": [640, 480], + "y_min":300, + "y_max":465, "fps": 40, "shutter_milliseconds":6, "contrast_limit":3.0, @@ -9,7 +11,9 @@ "removed_top_bins":3, "pitch_min":0, "pitch_step":1, + "laser_threshold":165, "height_scale":5, - "width_scale" :0.5 + "width_scale" :0.5, + "roughness_scale":5.0 } diff --git a/linescan.py b/linescan.py index 68e50af..010efd6 100755 --- a/linescan.py +++ b/linescan.py @@ -66,12 +66,12 @@ while True: # crop down to some rectangular bar used for processing # cropped_frame=frame[100:280,0:640] - cropped_frame=frame[0:480,0:640] + cropped_frame=frame[conf['y_min']:conf['y_max'],5:-5] # histogram output - # crop single line for color histogram output - line_frame=cropped_frame[140:141,5:635] + # crop single line near bottom for color histogram output + line_frame=cropped_frame[-2:-1,:] # compute b/w histogram line_frame = cv2.cvtColor(line_frame, cv2.COLOR_BGR2GRAY) histogram=np.zeros(histogram_steps,dtype=np.uint16) @@ -93,10 +93,8 @@ while True: # gather depth data from a laser line projection gray=cv2.cvtColor(cropped_frame, cv2.COLOR_BGR2GRAY) grad_y = cv2.Sobel(gray, cv2.CV_8U, 0, 2, ksize=5, scale=-.1, delta=0, borderType=cv2.BORDER_DEFAULT) - _, laser = cv2.threshold(grad_y, 165, 255, cv2.THRESH_BINARY) + _, laser = cv2.threshold(grad_y, conf['laser_threshold'], 255, cv2.THRESH_BINARY) weights=np.arange(laser.shape[0],dtype=float) - laser[0:400][0:640]=0 - laser[478:480][0:640]=0 weighted=np.tensordot(laser,weights,[[0],[0]]) count =np.sum (laser.astype(float),0) @@ -108,16 +106,18 @@ while True: baseline=np.percentile(depths,95) depths=depths[depths<baseline-2] - depth_min =np.min(depths) + depth_min =np.percentile(depths,5) depth_mean =np.mean(depths) depth_width =np.sum(depths>0) depth_height=baseline-depth_mean + depth_roughness=np.std(depths) - print("baseline "+str(baseline)+" min "+str(depth_min)+" mean "+str(depth_mean)+" width "+str(depth_width)+" height "+str(depth_height)) + print("baseline "+str(baseline)+" min "+str(depth_min)+" mean "+str(depth_mean)+" width "+str(depth_width)+" height "+str(depth_height)+" roughness "+str(depth_roughness)) # send out mean width and height of the scanned pieces by MIDI CC 64 and 65. midi_output_queue.append(((0xB<<4), 64, int(depth_height*conf['height_scale']))) midi_output_queue.append(((0xB<<4), 65, int(depth_width *conf['width_scale' ]))) + midi_output_queue.append(((0xB<<4), 66, int(depth_roughness *conf['roughness_scale' ]))) # impaint max to laser image (preview) laser[int(baseline+1)][:]=100 @@ -127,7 +127,7 @@ while True: cv2.imshow("laser", laser) # if the `q` key is pressed, break from the lop - key = cv2.waitKey(1) & 0xFF + key = cv2.waitKey(10) & 0xFF if key == ord("q"): break -- GitLab