วันศุกร์ที่ 28 กันยายน พ.ศ. 2561

ปัญหา และวิธีการแก้ (23 - 29 กันยายน 2561)

Problem & Solutoion
    1. ในตอน boot มีคำเตือนว่า 2.0716401 Under-voltage detected! ทำให้ใช้ rasberry pi และตัว kinnect ไม่ได้เนื่องจากไฟไม่พอ


    Solution : เปลื่ยนตัว adapter ที่สามารถจ่ายไฟ 2 A ได้ เพื่อจะได้เพียงพอกับตัว rasberry pi

    Result : สามารถกลับมาใช้ได้ปกติ, การทำงานของโค้ดนั้นรวดเร็วมากขึ้น, ส่วนของ Video Youtube ที่เคยทำให้ Framerate ตกลงนั้นลดลง และ การสั่งการและตรวจจับการเคลื่อนไหวตอบสนองได้เร็วขึ้น

วันพฤหัสบดีที่ 27 กันยายน พ.ศ. 2561

การเปลี่ยนการแสดงผลหน้าจอของ Rasberry Pi ให้เป็นแนวนอน

โดยใช้คำสั่งดังนี้

    1. ใช้คำสั่ง sudo nano /boot/config.txt
    2. ใส่ค่า display_rotate = 1 (display_rotate = 0 จะเป็นการแสดงแบบปกติ)
    3. กด Crtl + x เพื่อ save และพิมพ์คำสั่ง reboot
    4. กด Enter เพื่อยืนยัน
    5. ใช้คำสั่ง reboot



ผลที่ได้

วันเสาร์ที่ 15 กันยายน พ.ศ. 2561

ทดสอบโค้ดตรวจจับมือผ่านกล้องของ Notebook

เนื่องจากอุปกรณ์ Kinect ที่ใช้ยังพบปัญหาอยู่จึงได้ทดลองหาโค้ดอื่นที่พอใช้ได้มาทดสอบเกี่ยวกับการทำ Hand Detection ซึ่งในที่นี้จะใช้โค้ดของภาษา Python + OpenCV2 ร่วมกับการใช้กล้องของตัว Notebook เอง และได้ผลดังนี้

 

จากภาพจะพบว่าการทำงานจะเป็นการตรวจสอบเฉพาะบริเวณกรอบสี่เหลี่ยมที่เรากำหนดไว้ โดยภาพที่ได้มาก็จะมีลักษณะตามกรอบด้านซ้ายซึ่งเห็นเป็นรูปมือได้ค่อนข้างชัดเจน

ปัญหาที่พบคือ เนื่องจากตัวกล้องนั้นไม่ใช่ Depth Camera การกำหนดระยะ Threshold ในโค้ดจึงช่วยให้การตรวจจับยังไม่ดีเท่าที่ควร อีกทั้งหากพื้นหลังมีแสงรบกวนมากหรือไม่ใช่พื้นที่ราบเรียบ การตรวจจับจะเพี้ยนไปดังรูปด้านบน

ตัวอย่างโค้ดที่นำมาทดลอง

# organize imports import cv2 import imutils import numpy as np # global variables bg = None #------------------------------------------------------------------------------- # Function - To find the running average over the background #------------------------------------------------------------------------------- def run_avg(image, aWeight): global bg # initialize the background if bg is None: bg = image.copy().astype("float") return # compute weighted average, accumulate it and update the background cv2.accumulateWeighted(image, bg, aWeight) #------------------------------------------------------------------------------- # Function - To segment the region of hand in the image #------------------------------------------------------------------------------- def segment(image, threshold=25): global bg # find the absolute difference between background and current frame diff = cv2.absdiff(bg.astype("uint8"), image) # threshold the diff image so that we get the foreground thresholded = cv2.threshold(diff, threshold, 255, cv2.THRESH_BINARY)[1] # get the contours in the thresholded image (_, cnts, _) = cv2.findContours(thresholded.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # return None, if no contours detected if len(cnts) == 0: return else: # based on contour area, get the maximum contour which is the hand segmented = max(cnts, key=cv2.contourArea) return (thresholded, segmented) #------------------------------------------------------------------------------- # Main function #------------------------------------------------------------------------------- if __name__ == "__main__": # initialize weight for running average aWeight = 0.5 # get the reference to the webcam camera = cv2.VideoCapture(0) # region of interest (ROI) coordinates top, right, bottom, left = 10, 350, 225, 590 # initialize num of frames num_frames = 0 # keep looping, until interrupted while(True): # get the current frame (grabbed, frame) = camera.read() # resize the frame frame = imutils.resize(frame, width=700) # flip the frame so that it is not the mirror view frame = cv2.flip(frame, 1) # clone the frame clone = frame.copy() # get the height and width of the frame (height, width) = frame.shape[:2] # get the ROI roi = frame[top:bottom, right:left] # convert the roi to grayscale and blur it gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (7, 7), 0) # to get the background, keep looking till a threshold is reached # so that our running average model gets calibrated if num_frames < 30: run_avg(gray, aWeight) else: # segment the hand region hand = segment(gray) # check whether hand region is segmented if hand is not None: # if yes, unpack the thresholded image and # segmented region (thresholded, segmented) = hand # draw the segmented region and display the frame cv2.drawContours(clone, [segmented + (right, top)], -1, (0, 0, 255)) cv2.imshow("Thesholded", thresholded) # draw the segmented hand cv2.rectangle(clone, (left, top), (right, bottom), (0,255,0), 2) # increment the number of frames num_frames += 1 # display the frame with segmented hand cv2.imshow("Video Feed", clone) # observe the keypress by the user keypress = cv2.waitKey(1) & 0xFF # if the user pressed "q", then stop looping if keypress == ord("q"): break # free up memory camera.release() cv2.destroyAllWindows()

วันศุกร์ที่ 7 กันยายน พ.ศ. 2561

การทดลองใช้โค้ดจากงานเก่า part 1

ก่อนที่เราจะสามารถใช้ฟังก์ชัน keymap ได้ เราจะต้องทำขั้นตอนดังนี้
   1. sudo apt-get install freenect
   2. sudo apt-cache search freenect
   3. sudo apt-get install python-freenect
   4. pip install pynput




และจากนั้นก็เหมือนจะมีปัญหาในการเรียกเว็บหน้า browser 

                           

เราจึงเปลี่ยนคำสั่งที่ใช้
     จาก
os.system("chromium-browser --app=file:///home/pi/Desktop/kinect_hand_detection_and_tracking/src/index.html")
       เป็น
webbrowser.open('file://' + os.path.realpath("/home/pi/Desktop/kinect_hand_detection_and_tracking/src/index.html"))


วันอังคารที่ 4 กันยายน พ.ศ. 2561

การทดลองใช้ Kinect Xbox 360 บน Window ผ่าน Toolkit

สิ่งที่ต้องเตรียมในการทดสอบ

  • กล้อง Kinect Xbox 360
  • สาย usb adapter
  • Kinect for Windows SDK v1.7
  • Kinect for Windows Developer Toolkit v1.7
  • KinectSDK-v1.0-beta2-x64
  • ที่ต้องใช้ตัว SDK beta และ Kinect for Windows v1.7 เนื่องจากตัว Kinect Xbox 360 รองรับเฉพาะเวอร์ชั่นดังกล่าว

ขั้นตอนการทดสอบ

  1. ทำการดาวน์โหลด SDK ของ Kinect เพื่อติดตั้งตัว Module ต่างๆของ Kinect จากเว็บ
    https://www.microsoft.com/en-ca/download/details.aspx?id=27876


  2. ทำการดาวน์โหลด Kinect for Windows SDK เพื่อใช้ร่วมกับ Developer Toolkit จากเว็บ
    https://www.microsoft.com/en-us/download/details.aspx?id=36996


  3. ทำการดาวน์โหลด Kinect for Windows Developer Toolkit จากเว็บ


  4. เมื่อโหลดครบทั้ง3ตัวแล้ว ให้ทำการติดตั้งโปรแกรมทั้ง 3 ลงเครื่องและทำการ Restart คอมพิวเตอร์เพื่อให้การติดตั้ง Driver ของ Kinect ให้สมบูรณ์ซึ่งสามารถตรวจสอบได้จาก
    Device Manager


  5. เปิดตัว Developer Toolkit ขึ้นมาจะได้หน้าจอดังนี้ ซึ่งเราสามารถทดสอบระบบที่เราต้องการจากกล้องได้


  6. ทำการทดสอบการจับภาพปกติจากโหมด Color Basics-D2D


  7. ทำการทดสอบการจับภาพความลึกจากโหมด Depth Basics-D2D แต่พบว่าภาพที่ได้มีความเพี้ยนค่อนข้างมากอาจเป็นผลจากตำแหน่งการตั้งกล้องและแสงภายในห้องทำให้ผลที่ได้มีลักษณะผิดแปลกไป



  8. ทำการทดสอบการจับภาพทั้งโหมดปกติและโหมดความลึกในเวลาเดียวกันจากโหมด Kinect Explorer-D2D ซึ่งสามารถตรวจจับเสียงและสร้างภาพโครงร่างหรือ Skeleton ได้ ส่วนตัวเลขด้านบนขวาของจอคือ FPS ของการตรวจจับ