diff --git a/data.csv b/data.csv index 25a9f84..8752590 100644 --- a/data.csv +++ b/data.csv @@ -1,80 +1,150 @@ -3.495320154929491423e+02,2.330079425878373058e+02 -1.900000000000000000e+02,4.500000000000000000e+00 -1.700000000000000000e+01,1.100000000000000000e+01 -5.335000000000000000e+02,1.150000000000000000e+01 -5.605000000000000000e+02,2.300000000000000000e+01 -2.070000000000000000e+02,3.100000000000000000e+01 -3.886666666666666856e+02,3.266666666666666430e+01 -6.400000000000000000e+01,4.750000000000000000e+01 -2.645000000000000000e+02,5.650000000000000000e+01 -2.035000000000000000e+02,5.950000000000000000e+01 -6.980000000000000000e+02,7.450000000000000000e+01 -1.800000000000000000e+01,7.800000000000000000e+01 -2.860000000000000000e+02,8.350000000000000000e+01 -4.925000000000000000e+02,8.600000000000000000e+01 -1.440000000000000000e+02,1.000000000000000000e+02 -4.070000000000000000e+02,1.040000000000000000e+02 -2.200000000000000000e+01,1.120000000000000000e+02 -4.475000000000000000e+02,1.135000000000000000e+02 -4.760000000000000000e+02,1.130000000000000000e+02 -5.700000000000000000e+02,1.160000000000000000e+02 -6.510000000000000000e+02,1.185000000000000000e+02 -3.015000000000000000e+02,1.240000000000000000e+02 -5.663333333333333712e+02,1.253333333333333286e+02 -6.275000000000000000e+02,1.270000000000000000e+02 -6.620000000000000000e+02,1.285000000000000000e+02 -3.210000000000000000e+02,1.345000000000000000e+02 -3.770000000000000000e+02,1.400000000000000000e+02 -2.430000000000000000e+02,1.470000000000000000e+02 -1.217500000000000000e+02,1.550000000000000000e+02 -1.760000000000000000e+02,1.560000000000000000e+02 -4.595000000000000000e+02,1.560000000000000000e+02 -4.380000000000000000e+02,1.600000000000000000e+02 -1.100000000000000000e+02,1.635000000000000000e+02 -4.783333333333333570e+01,1.731666666666666572e+02 -4.353333333333333144e+02,1.743333333333333428e+02 -4.905000000000000000e+02,1.775000000000000000e+02 -1.645000000000000000e+02,1.930000000000000000e+02 -5.940000000000000000e+02,2.055000000000000000e+02 -3.287189349112426271e+02,2.242278106508875624e+02 -6.635000000000000000e+02,2.140000000000000000e+02 -1.170000000000000000e+02,2.325000000000000000e+02 -4.150000000000000000e+02,2.360000000000000000e+02 -2.980000000000000000e+02,2.395000000000000000e+02 -2.575000000000000000e+02,2.445000000000000000e+02 -3.715000000000000000e+02,2.560000000000000000e+02 -3.900000000000000000e+02,2.565000000000000000e+02 -6.928571428571429180e+01,2.700000000000000000e+02 -4.220000000000000000e+02,2.690000000000000000e+02 -4.920000000000000000e+02,2.715000000000000000e+02 -2.643333333333333144e+02,2.886666666666666856e+02 -4.710000000000000000e+02,2.890000000000000000e+02 -2.245000000000000000e+02,2.935000000000000000e+02 -2.378750000000000000e+02,2.993125000000000000e+02 -3.770000000000000000e+02,2.960000000000000000e+02 -4.766666666666666856e+02,3.086666666666666856e+02 -3.445000000000000000e+02,3.105000000000000000e+02 -1.100000000000000000e+02,3.170000000000000000e+02 -2.110000000000000000e+02,3.165000000000000000e+02 -3.495000000000000000e+02,3.290000000000000000e+02 -4.008888888888889142e+02,3.303333333333333144e+02 -5.615000000000000000e+02,3.415000000000000000e+02 -4.515000000000000000e+02,3.555000000000000000e+02 -1.450000000000000000e+02,3.585000000000000000e+02 -4.460000000000000000e+02,3.615000000000000000e+02 -4.178333333333333144e+02,3.671666666666666856e+02 -1.000000000000000000e+01,3.770000000000000000e+02 -2.450000000000000000e+02,3.760000000000000000e+02 -5.375000000000000000e+02,3.950000000000000000e+02 -4.510000000000000000e+02,4.030000000000000000e+02 -4.260000000000000000e+02,4.070000000000000000e+02 -3.096666666666666856e+02,4.133333333333333144e+02 -2.170000000000000000e+02,4.250000000000000000e+02 -3.566666666666666856e+02,4.343333333333333144e+02 -3.776666666666666856e+02,4.343333333333333144e+02 -3.190000000000000000e+02,4.420000000000000000e+02 -3.230000000000000000e+02,4.435000000000000000e+02 -3.596666666666666856e+02,4.443333333333333144e+02 -2.020000000000000000e+02,4.540000000000000000e+02 -2.800000000000000000e+02,4.630000000000000000e+02 -4.625000000000000000e+02,4.640000000000000000e+02 +5.112092395616320459e+02,3.841483241281525238e+02 +7.200000000000000000e+01,2.050000000000000000e+01 +1.536666666666666572e+02,1.866666666666666785e+01 +7.341250000000000000e+02,2.012500000000000000e+01 +3.970000000000000000e+02,2.300000000000000000e+01 +9.562500000000000000e+02,2.333333333333333215e+01 +9.745000000000000000e+02,2.600000000000000000e+01 +3.827142857142857224e+02,3.550000000000000000e+01 +7.655000000000000000e+02,3.600000000000000000e+01 +1.410000000000000000e+02,3.800000000000000000e+01 +5.240000000000000000e+02,4.500000000000000000e+01 +1.507333333333333201e+02,4.833333333333333570e+01 +3.925000000000000000e+02,4.650000000000000000e+01 +7.126666666666666288e+02,5.566666666666666430e+01 +5.185000000000000000e+02,5.850000000000000000e+01 +2.463333333333333428e+02,6.566666666666667140e+01 +4.515000000000000000e+02,7.050000000000000000e+01 +6.090000000000000000e+02,7.964705882352940591e+01 +5.840000000000000000e+02,8.500000000000000000e+01 +8.230000000000000000e+02,9.000000000000000000e+01 +1.756666666666666572e+02,1.006666666666666714e+02 +9.265000000000000000e+02,1.035000000000000000e+02 +7.110000000000000000e+02,1.100000000000000000e+02 +8.105000000000000000e+02,1.210000000000000000e+02 +1.180000000000000000e+02,1.252857142857142918e+02 +7.535000000000000000e+02,1.335000000000000000e+02 +8.560000000000000000e+02,1.325000000000000000e+02 +7.870000000000000000e+02,1.362857142857142776e+02 +3.350000000000000000e+01,1.425000000000000000e+02 +5.906000000000000227e+02,1.611999999999999886e+02 +6.720000000000000000e+02,1.620000000000000000e+02 +7.340000000000000000e+02,1.660000000000000000e+02 +3.525000000000000000e+01,1.800000000000000000e+02 +7.948750000000000000e+02,1.838750000000000000e+02 +1.550000000000000000e+02,1.840000000000000000e+02 +5.683999999999999773e+02,1.901999999999999886e+02 +7.915000000000000000e+02,1.905000000000000000e+02 +2.897500000000000000e+02,1.930000000000000000e+02 +3.150000000000000000e+02,1.980000000000000000e+02 +4.237318718381113172e+02,2.235463743676222634e+02 +6.310000000000000000e+02,2.030000000000000000e+02 +5.583333333333333712e+02,2.083333333333333428e+02 +1.050000000000000000e+02,2.130000000000000000e+02 +2.850000000000000000e+02,2.125000000000000000e+02 +6.900000000000000000e+01,2.150000000000000000e+02 +2.815000000000000000e+02,2.280000000000000000e+02 +5.945790604026846040e+02,2.768861744966442870e+02 +9.056666666666666288e+02,2.323333333333333428e+02 +1.381666666666666572e+02,2.348333333333333428e+02 +5.600000000000000000e+01,2.427142857142857224e+02 +4.125000000000000000e+02,2.435000000000000000e+02 +3.642500000000000000e+02,2.540000000000000000e+02 +1.710000000000000000e+02,2.610000000000000000e+02 +7.850000000000000000e+01,2.625000000000000000e+02 +9.405000000000000000e+02,2.665000000000000000e+02 +1.020000000000000000e+02,2.730000000000000000e+02 +4.860000000000000000e+02,2.720000000000000000e+02 +4.595000000000000000e+02,2.760000000000000000e+02 +8.100000000000000000e+01,2.770000000000000000e+02 +5.077500000000000000e+02,2.800000000000000000e+02 +4.593999999999999773e+02,2.841999999999999886e+02 +9.450000000000000000e+02,2.860000000000000000e+02 +7.250000000000000000e+02,2.930000000000000000e+02 +3.371250000000000000e+02,2.961250000000000000e+02 +6.890000000000000000e+02,2.940000000000000000e+02 +1.277999999999999972e+02,2.985000000000000000e+02 +4.545000000000000000e+02,3.070000000000000000e+02 +4.755531914893617227e+02,3.122765957446808329e+02 +6.765000000000000000e+02,3.090000000000000000e+02 +8.133333333333332860e+01,3.166666666666666856e+02 +4.500909090909090651e+02,3.266363636363636260e+02 +1.004500000000000000e+03,3.330000000000000000e+02 +6.250000000000000000e+02,3.430000000000000000e+02 +5.425000000000000000e+02,3.520000000000000000e+02 +4.730000000000000000e+02,3.530000000000000000e+02 +3.350000000000000000e+02,3.540000000000000000e+02 +7.840000000000000000e+02,3.580000000000000000e+02 +1.180000000000000000e+02,3.625000000000000000e+02 +1.580000000000000000e+02,3.630000000000000000e+02 +4.605000000000000000e+02,3.790000000000000000e+02 +2.970000000000000000e+02,3.850000000000000000e+02 +9.500000000000000000e+00,3.930000000000000000e+02 +7.000000000000000000e+01,3.920000000000000000e+02 +1.181111111111111143e+02,4.043333333333333144e+02 +8.170000000000000000e+02,4.080000000000000000e+02 +1.370000000000000000e+02,4.160000000000000000e+02 +1.045000000000000000e+02,4.330000000000000000e+02 +2.420000000000000000e+02,4.335000000000000000e+02 +5.237142857142856656e+02,4.330000000000000000e+02 +7.970000000000000000e+02,4.330000000000000000e+02 +9.450000000000000000e+01,4.400000000000000000e+02 +8.950000000000000000e+01,4.485000000000000000e+02 +9.200000000000000000e+01,4.630000000000000000e+02 +5.345000000000000000e+02,4.640000000000000000e+02 +3.120000000000000000e+02,4.770000000000000000e+02 +9.695000000000000000e+02,4.800000000000000000e+02 +9.045000000000000000e+02,4.820000000000000000e+02 +9.400000000000000000e+01,4.900000000000000000e+02 +1.341250000000000000e+02,4.928750000000000000e+02 +4.800000000000000000e+02,4.930000000000000000e+02 +7.265000000000000000e+02,4.960000000000000000e+02 +1.120000000000000000e+02,4.962500000000000000e+02 +9.296000000000000227e+02,4.968000000000000114e+02 +4.155000000000000000e+02,5.125000000000000000e+02 +6.540000000000000000e+02,5.170000000000000000e+02 +2.723999999999999773e+02,5.202000000000000455e+02 +8.805000000000000000e+02,5.195000000000000000e+02 +1.007000000000000000e+03,5.180000000000000000e+02 +5.445000000000000000e+02,5.245000000000000000e+02 +3.260000000000000000e+02,5.310000000000000000e+02 +6.390000000000000000e+02,5.325000000000000000e+02 +5.504117647058823195e+02,5.361176470588235361e+02 +4.197333333333333485e+02,5.433333333333333712e+02 +8.233333333333333712e+02,5.436666666666666288e+02 +3.705000000000000000e+02,5.455000000000000000e+02 +8.550000000000000000e+02,5.470000000000000000e+02 +6.690000000000000000e+02,5.510000000000000000e+02 +6.330000000000000000e+02,5.580000000000000000e+02 +6.190000000000000000e+02,5.855000000000000000e+02 +7.380000000000000000e+02,5.862500000000000000e+02 +1.940000000000000000e+02,5.910000000000000000e+02 +4.411666666666666856e+02,5.918333333333333712e+02 +4.870000000000000000e+02,6.025000000000000000e+02 +9.090000000000000000e+02,6.030000000000000000e+02 +5.665000000000000000e+02,6.050000000000000000e+02 +8.526666666666666288e+02,6.146666666666666288e+02 +2.085000000000000000e+02,6.260000000000000000e+02 +5.055789473684210407e+02,6.268947368421053170e+02 +6.745000000000000000e+02,6.285000000000000000e+02 +4.926999999999999886e+02,6.461000000000000227e+02 +8.506000000000000227e+02,6.542000000000000455e+02 +9.393333333333333712e+02,6.553333333333333712e+02 +2.710000000000000000e+02,6.562500000000000000e+02 +3.468750000000000000e+02,6.588750000000000000e+02 +3.535000000000000000e+02,6.595000000000000000e+02 +7.910000000000000000e+02,6.680000000000000000e+02 +3.396666666666666856e+02,6.783333333333333712e+02 +2.966000000000000227e+02,6.872000000000000455e+02 +4.200000000000000000e+01,6.910000000000000000e+02 +2.325000000000000000e+02,6.905000000000000000e+02 +8.375000000000000000e+02,7.010000000000000000e+02 +6.710000000000000000e+02,7.130000000000000000e+02 +3.070000000000000000e+02,7.190000000000000000e+02 +8.005000000000000000e+02,7.255000000000000000e+02 +6.345000000000000000e+02,7.315000000000000000e+02 +3.220000000000000000e+02,7.360000000000000000e+02 +1.040000000000000000e+02,7.380000000000000000e+02 +1.025000000000000000e+02,7.435000000000000000e+02 +2.385000000000000000e+02,7.570000000000000000e+02 +6.400000000000000000e+01,7.595000000000000000e+02 diff --git a/test.py b/test.py index c6161d1..922b297 100644 --- a/test.py +++ b/test.py @@ -10,7 +10,7 @@ from osc4py3 import oscbuildparse osc_startup() osc_udp_client("127.0.0.1", 57120, "local") -note_C = oscbuildparse.OSCMessage("/notes", None, ["C",440]) +#note = oscbuildparse.OSCMessage("/notes", None, ["C",440]) # note_Db = oscbuildparse.OSCMessage("/note_Db", None, ["text"]) # note_D = oscbuildparse.OSCMessage("/note_D", None, ["text"]) @@ -23,16 +23,28 @@ note_C = oscbuildparse.OSCMessage("/notes", None, ["C",440]) # note_A = oscbuildparse.OSCMessage("/note_A", None, ["text"]) # note_Bb = oscbuildparse.OSCMessage("/note_Bb", None, ["text"]) # note_B = oscbuildparse.OSCMessage("/note_B", None, ["text"]) - +def resize(img): + width = 1024 + height = 768 + dim = (width, height) + resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) + return resized #import imutils CONNECTIVITY = 4 DRAW_CIRCLE_RADIUS = 5 -imageorg = cv2.imread('testimage.jpg') -imageorginal = cv2.imread('testimage.jpg') +imageorg = cv2.imread('testimage3.jpg') +cv2.namedWindow('image',cv2.WINDOW_NORMAL) +#cv2.resizeWindow('image', 600,600) +imageorg = resize(imageorg) +#imageorginal = cv2.imread('testimage4.jpg') gray = cv2.cvtColor(imageorg, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY)[1] height, width, channels = imageorg.shape + + + + # perform a series of erosions and dilations to remove # any small blobs of noise from the thresholded image # thresh = cv2.erode(thresh, None, iterations=2) @@ -110,8 +122,8 @@ for x in range(int(height / 2)): if (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int(width/2),0,int((width / 2) + int(height / 2) / 2), int(height / 2 - numpy.sqrt(3)*int(height / 2)/2)): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (0, 255, 0), thickness=1) testCount+=1 - osc_send(note_C, "local") - osc_process() + note = oscbuildparse.OSCMessage("/notes", None, ["C",261.63,60]) + osc_send(note, "local") #print(testCount) distance[3] = 1 # elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) + int(height / 2) / 2), int(height / 2 - numpy.sqrt(3)*int(height / 2)/2),int((width / 2) + numpy.sqrt(3)*int(height / 2)/2), int(height / 2 - int(height / 2) / 2)): @@ -121,7 +133,8 @@ for x in range(int(height / 2)): # distance[3] = 1 elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) + numpy.sqrt(3)*int(height / 2)/2), int(height / 2 - int(height / 2) / 2),int(width/2 + height / 2), int(height / 2)): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (50, 150, 20), thickness=1) - #osc_send(note_D, "local") + note = oscbuildparse.OSCMessage("/notes", None, ["D",293.66,62]) + osc_send(note, "local") #osc_process() distance[3] = 1 # elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int(width/2 + height / 2), int(height / 2),int((width / 2) + numpy.sqrt(3)*int(height / 2)/2), int(height / 2 + int(height / 2) / 2)): @@ -131,12 +144,14 @@ for x in range(int(height / 2)): # distance[3] = 1 elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) + numpy.sqrt(3)*int(height / 2)/2), int(height / 2 + int(height / 2) / 2),int((width / 2) + int(height / 2) / 2), int(height / 2 + numpy.sqrt(3)*int(height / 2)/2)): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (200, 200, 50), thickness=1) - #osc_send(note_E, "local") + note = oscbuildparse.OSCMessage("/notes", None, ["E",329.63,64]) + osc_send(note, "local") #osc_process() distance[3] = 1 elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) + int(height / 2) / 2), int(height / 2 + numpy.sqrt(3)*int(height / 2)/2),int(width / 2),int(height)): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (200, 200, 200), thickness=1) - #osc_send(note_F, "local") + note = oscbuildparse.OSCMessage("/notes", None, ["F",349.23,65]) + osc_send(note, "local") #osc_process() distance[3] = 1 # elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int(width / 2),int(height),int((width / 2) - int(height / 2) / 2), int(height / 2 + numpy.sqrt(3)*int(height / 2)/2)): @@ -146,7 +161,8 @@ for x in range(int(height / 2)): # distance[3] = 1 elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) - int(height / 2) / 2), int(height / 2 + numpy.sqrt(3)*int(height / 2)/2),int((width / 2) - numpy.sqrt(3)*int(height / 2)/2), int(height / 2 + int(height / 2) / 2)): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (0, 250, 200), thickness=1) - #osc_send(note_G, "local") + note = oscbuildparse.OSCMessage("/notes", None, ["G",392.00,67]) + osc_send(note, "local") #osc_process() distance[3] = 1 # elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) - numpy.sqrt(3)*int(height / 2)/2), int(height / 2 + int(height / 2) / 2),int((width / 2) - (height / 2)),int(height / 2) ): @@ -156,7 +172,8 @@ for x in range(int(height / 2)): # distance[3] = 1 elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) - (height / 2)),int(height / 2),int((width / 2) - numpy.sqrt(3)*int(height / 2)/2), int(height / 2 - int(height / 2) / 2) ): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (0,150, 250), thickness=1) - #osc_send(note_A, "local") + note = oscbuildparse.OSCMessage("/notes", None, ["A",440.00,69]) + osc_send(note, "local") #osc_process() distance[3] = 1 # elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) - numpy.sqrt(3)*int(height / 2)/2), int(height / 2 - int(height / 2) / 2),int((width / 2) - int(height / 2) / 2), int(height / 2 - numpy.sqrt(3)*int(height / 2)/2) ): @@ -166,12 +183,15 @@ for x in range(int(height / 2)): # distance[3] = 1 elif (distance[3]==0) and (distance[2] <= x) and inArea(int(distance[0]),int(distance[1]),int(width/2),int(height/2),int((width / 2) - int(height / 2) / 2), int(height / 2 - numpy.sqrt(3)*int(height / 2)/2),int(width / 2),0 ): cv2.circle(imageorg, (int(distance[0]),int(distance[1])), DRAW_CIRCLE_RADIUS, (50,250, 250), thickness=1) - #osc_send(note_B, "local") + note = oscbuildparse.OSCMessage("/notes", None, ["B",493.88,71]) + osc_send(note, "local") #osc_process() distance[3] = 1 + + osc_process() #cv2.circle(imageorg, (389,33), DRAW_CIRCLE_RADIUS, (0, 255, 0), thickness=1) - cv2.imshow('Overlay',drawingImage) + cv2.imshow('image',drawingImage) cv2.waitKey(100) #returns true if point is in triangle ABC diff --git a/testimage2.jpg b/testimage2.jpg new file mode 100644 index 0000000..7396f91 Binary files /dev/null and b/testimage2.jpg differ diff --git a/testimage3.jpg b/testimage3.jpg new file mode 100644 index 0000000..eebf929 Binary files /dev/null and b/testimage3.jpg differ diff --git a/testimage4.jpg b/testimage4.jpg new file mode 100644 index 0000000..8515103 Binary files /dev/null and b/testimage4.jpg differ