- OpenCV 4 with Python Blueprints
- Dr. Menua Gevorgyan Arsen Mamikonyan Michael Beyeler
- 238字
- 2021-06-24 16:50:03
Tracking hand gestures in real time
Hand gestures are analyzed by the recognize function; this is where the real magic takes place. This function handles the entire process flow, from the raw grayscale image to a recognized hand gesture. It returns the number of fingers and the illustration frame. It implements the following procedure:
- It extracts the user's hand region by analyzing the depth map (img_gray), and returns a hand region mask (segment), like this:
def recognize(img_gray: np.ndarray) -> Tuple[int,np.ndarray]:
# segment arm region
segment = segment_arm(img_gray)
- It performs contour analysis on the hand region mask (segment). Then, it returns the largest contour found in the image (contour) and any convexity defects (defects), as follows:
# find the hull of the segmented area, and based on that find the
# convexity defects
contour, defects = find_hull_defects(segment)
- Based on the contour found and the convexity defects, it detects the number of extended fingers (num_fingers) in the image. Then, it creates an illustration image (img_draw) using (segment) image as a template, and annotates it with contour and defect points, like this:
img_draw = cv2.cvtColor(segment, cv2.COLOR_GRAY2RGB)
num_fingers, img_draw = detect_num_fingers(contour,
defects, img_draw)
- Finally, the estimated number of extended fingers (num_fingers), as well as the annotated output image (img_draw), are returned, as follows:
return num_fingers, img_draw
In the next section, let's learn how to accomplish hand region segmentation, which we used at the beginning of the procedure.
推薦閱讀
- JSP開發(fā)案例教程
- Clojure Reactive Programming
- Visual FoxPro程序設(shè)計(jì)習(xí)題集及實(shí)驗(yàn)指導(dǎo)(第四版)
- 打開Go語言之門:入門、實(shí)戰(zhàn)與進(jìn)階
- Java零基礎(chǔ)實(shí)戰(zhàn)
- Android群英傳
- R數(shù)據(jù)科學(xué)實(shí)戰(zhàn):工具詳解與案例分析
- Arduino計(jì)算機(jī)視覺編程
- Tableau Desktop可視化高級應(yīng)用
- Python預(yù)測分析實(shí)戰(zhàn)
- Android高級開發(fā)實(shí)戰(zhàn):UI、NDK與安全
- 程序員必會(huì)的40種算法
- 輕松學(xué)Scratch 3.0 少兒編程(全彩)
- JavaScript編程精解(原書第3版)
- Python深度學(xué)習(xí):基于PyTorch