Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LEGO BOOST で大人も遊ぼう! 〜ラズパイカメラ連携編〜

LEGO BOOST で大人も遊ぼう! 〜ラズパイカメラ連携編〜

「札幌で開催!IoT縛りの勉強・発表会! Vol.05」で発表した資料。

F82dff1a913e41652f060122fd921822?s=128

MinoruInachi

January 20, 2019
Tweet

Transcript

  1. -&(0#0045Ͱ
 େਓ΋༡΅͏ʂ ʙϥζύΠΧϝϥ࿈ܞฤʙ

  2. ࣗݾ঺հ ීஈ͸ΤϯλʔϓϥΠζܥͷιϑτ΢ΣΞΤϯδχΞ ಀආ׆ಈͱͯ͠ϚΠίϯϘʔυܥ΋ &5ϩϘίϯ๺ւಓ஍۠ɹ࣮ߦҕһ 1ZUIPOࡳຈཪํ

  3. ˞೥݄೔ݱࡏ

  4. ̏छྨͷ#0045ϒϩοΫ Ϝʔϒϋϒ ֎෦Ϟʔλʔ Χϥʔˍڑ཭ηϯαʔ ಺ଂϞʔλʔY ಺ଂνϧτηϯαʔ 3(#-&%

  5. BLE ίϚϯυ ௨஌ ϓϩάϥϜ͕ಈ͘ ͷ͸ΞϓϦ্

  6. https://github.com/JorgePe/BOOSTreveng #-&ͷ௨৴಺༰͸େํղੳ͞Ε͍ͯΔ

  7. https://github.com/JorgePe/pyb00st 1ZUIPOͷ"1*΋͋Δ QZCTU ˞ଞʹOPEFKT +BWB4DSJQU ͷ"1*΋͋Δ

  8. https://qiita.com/sonoisa/items/cf0bc6c0ed4d244407b4 εϚʔτϩοΫ࣮ݱͨ͠ڧऀ΋͍Δ

  9. ΧϝϥϞδϡʔϧ 3BTQCFSSZ1J;FSP8 ʢը૾ॲཧɺߦಈ൑ఆʣ #-& ʢಈ࡞ࢦࣔʣ ࠓճ΍ͬͯΈͨ͜ͱ ※εΠοναΠΤϯεͰͷՁ֨ʢ2019೥1݄19೔ݱࡏʣ ɹRaspberry Pi Zero

    W 1,296ԁ
 ɹRaspberry Pi ΧϝϥϞδϡʔϧ V2 4,680ԁ ɹRaspberry Pi Zero έʔε 648ԁ ͍ΘΏΔʮϚγϯϏδϣϯʯͷ·Ͷ͝ͱ
 https://ja.wikipedia.org/wiki/ϚγϯϏδϣϯ
  10. None
  11. None
  12. ϥζύΠΧϝϥ͔Βͷը૾࿈ଓऔΓࠐΈ import picamera import picamera.array import cv2 import time :

    with picamera.PiCamera() as camera: camera.resolution = (160, 120) # 160x120ͷղ૾౓ time.sleep(2) with picamera.array.PiRGBArray(camera) as frame: time.sleep(0.1) for frame in camera.capture_continuous(frame, 'bgr', use_video_port=True): image = frame.array # ͜͜Ͱ֤ϑϨʔϜͷΠϝʔδΛॲཧʢOpenCV 2Λར༻ʣ
  13. roi = image[60:120, 0:160] # ؔ৺ྖҬͷ੾Γग़͠ ݩͷΠϝʔδ(image)

  14. mono = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) # ϞϊΫϩԽ blur = cv2.GaussianBlur(mono, (9,

    9), 0) # ฏ׈Խ
  15. ret,thresh = cv2.threshold(blur, 60, 255,cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU) # ೋ஋Խ erode_img = cv2.erode(thresh,

    None, iterations=2) # ऩॖ(Erosion) dilate_img = cv2.dilate(erode_img, None, iterations=2) # ๲ு(Dilation)
  16. _,contours,hierarchy = cv2.findContours(dilate_img, 1, 
 cv2.CHAIN_APPROX_NONE)# ྠֲݕग़ c = max(contours,

    key=cv2.contourArea) # ໘ੵ͕࠷େͷྠֲ M = cv2.moments(c) # Ϟʔϝϯτʢॏ৺ʣ cx = int(M[‘m10’]/M['m00']) # ॏ৺࠲ඪ x cy = int(M[‘m01']/M['m00']) # ॏ৺࠲ඪ y
  17. mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) : if cx >= 120:

    # ӈટճ (duty_a, duty_b) = (100, 10) elif cx > 50: # ௚ਐ (duty_a, duty_b) = (100, 100) elif cx > 0: # ࠨટճ (duty_a, duty_b) = (10, 100) else: # ఀࢭ (duty_a, duty_b) = (0, 0) mymovehub.run_motors_for_time(MOTOR_AB, 150, duty_a, duty_b)
  18. None
  19. None
  20. ·ͱΊ -&(0#0045ͷ௨৴͸΄΅ղੳࡁΈͰେਓ΋༡΂Δ #-&͕࢖͑Ε͹ͲΜͳػث͔ΒͰ΋ #-& Χϝϥ͕࢖͑ΔػثͱͳΒϚγϯϏδϣϯͰ͖Δ %FFQ3BDFSͷϚω͝ͱ͍ͨ͠