Advertisement
JoelSjogren

Untitled

Mar 28th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import sys
  2. from cv2 import *
  3. import rtmidi
  4.  
  5. window_name = "Drums"
  6. namedWindow( window_name, WINDOW_AUTOSIZE )
  7. moveWindow( window_name, 0, 0 )
  8.  
  9. cap = VideoCapture(1) # open the second camera
  10. if not cap.isOpened():
  11. sys.exit(1)
  12.  
  13. """
  14. drumkit = imread("drumkit2-transparent2.png", -1) # -1 for alpha
  15. drumkit = flip(drumkit, 1)
  16.  
  17. midiout = rtmidi.MidiOut()
  18. midiout.open_port(1)
  19. on = lambda x: [0x99, x, 127]
  20. off = lambda x: [0x89, x, 0]
  21. snare = 40
  22. def play(x):
  23. midiout.send_message(on(x))
  24. """
  25.  
  26.  
  27. while True:
  28. ret, im = cap.read()
  29. if not ret:
  30. sys.exit(1)
  31.  
  32. im = flip(im, 1)
  33.  
  34. imgray = cvtColor(im, COLOR_BGR2GRAY)
  35. ret,thresh = threshold(imgray,250,255,0)
  36. im2, contours, hierarchy = findContours(thresh, RETR_TREE, CHAIN_APPROX_SIMPLE)
  37.  
  38. """
  39. for i in contours:
  40. area = contourArea(i)
  41. #if (100 < area && area < 1000)
  42. color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) )
  43. drawContours( rotated, contours, i, color, 2, 8, hierarchy, 0, Point() )
  44. """
  45.  
  46. drawContours(im, contours, -1, (255,0,0), 3)
  47.  
  48. for i in contours:
  49. center, radius = minEnclosingCircle(i);
  50. #print(center, radius)
  51. circle(im, (int(center[0]), int(center[1])), int(radius), (0, 0, 255))
  52. #body.move(center, radius);
  53.  
  54. #body.draw(rotated);
  55.  
  56. #overlayImage(rotated, drumkit, vr, Point2i(-80, 100));
  57.  
  58. imshow( window_name, im );
  59. waitKey(5); # need timeout for images to be shown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement