Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from cv2 import *
- import rtmidi
- window_name = "Drums"
- namedWindow( window_name, WINDOW_AUTOSIZE )
- moveWindow( window_name, 0, 0 )
- cap = VideoCapture(1) # open the second camera
- if not cap.isOpened():
- sys.exit(1)
- """
- drumkit = imread("drumkit2-transparent2.png", -1) # -1 for alpha
- drumkit = flip(drumkit, 1)
- midiout = rtmidi.MidiOut()
- midiout.open_port(1)
- on = lambda x: [0x99, x, 127]
- off = lambda x: [0x89, x, 0]
- snare = 40
- def play(x):
- midiout.send_message(on(x))
- """
- while True:
- ret, im = cap.read()
- if not ret:
- sys.exit(1)
- im = flip(im, 1)
- imgray = cvtColor(im, COLOR_BGR2GRAY)
- ret,thresh = threshold(imgray,250,255,0)
- im2, contours, hierarchy = findContours(thresh, RETR_TREE, CHAIN_APPROX_SIMPLE)
- """
- for i in contours:
- area = contourArea(i)
- #if (100 < area && area < 1000)
- color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) )
- drawContours( rotated, contours, i, color, 2, 8, hierarchy, 0, Point() )
- """
- drawContours(im, contours, -1, (255,0,0), 3)
- for i in contours:
- center, radius = minEnclosingCircle(i);
- #print(center, radius)
- circle(im, (int(center[0]), int(center[1])), int(radius), (0, 0, 255))
- #body.move(center, radius);
- #body.draw(rotated);
- #overlayImage(rotated, drumkit, vr, Point2i(-80, 100));
- imshow( window_name, im );
- waitKey(5); # need timeout for images to be shown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement