Skip to content
Snippets Groups Projects
Commit be65da18 authored by dronus's avatar dronus
Browse files

output roughness, more parameters configurable (cropping etc.)

parent 62a4dd44
No related branches found
No related tags found
No related merge requests found
{
"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
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment