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

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

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

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

MinoruInachi

January 20, 2019
Tweet

More Decks by MinoruInachi

Other Decks in Technology

Transcript

  1. ΧϝϥϞδϡʔϧ 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/ϚγϯϏδϣϯ
  2. ϥζύΠΧϝϥ͔Βͷը૾࿈ଓऔΓࠐΈ 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Λར༻ʣ
  3. 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)
  4. _,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
  5. 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)