You can write about programming not only with prose, but also with verses. The latter, of course, does not happen often - say, on an Intel blog, this happened a little less than never. However, as an experiment today, we decided to allow ourselves; how it happened is up to you. So...
In the last quarter of the year
And to be precise, last week,
Intel developers introduced a new
Release OpenVINO toolkit on software .
What is new is done - refer to the changelog,
I cannot be precise in the details,
I will tell only a little in this post:
About vision, Intel and raspberry wine.
***
OpenVINO is essentially a set of tools,
Libraries and Solution Examples
With special acceleration on Intel's hardware
Popular computer vision tasks.
Who has not heard of computer vision -
This is a field of computer science,
Making the car understand
Like man, the world is around.
The source of information is mainly images,
And the problem is to create an algorithm
To extract useful traits
And making decisions on them.
***
The first in our mini-review is the OpenCV library,
How often is it called traditional
Machine vision and learning
Reading from the camera and on the drawing screen,
Cross-platform and living on GitHub,
Scored at the time of writing 30502 stars.
In the package for Raspberry, we also find
Public opencv and with it
NEON optimization, Python wrappers,
GStreamer for cameras and windows GTK.
***
Already seven years in the world
To solve our problems
Apply deep neural networks,
Those with a teacher need to be taught.
Caffe, PyTorch - it's all about training,
Sometimes taking a couple of weeks.
OpenVINO solves the second problem:
Run the trained grids as quickly as possible.
From the best solutions for many platforms,
For known scenarios, needs and resources,
In OpenVINO deep learning - a separate engine,
With one interface on different devices.
***
To work with your toolkit
Install the Raspbian 9 on the Raspberry Pi,
Connect Movidius stick, power supply,
Check that the CPU version is at least seven.
Read more in the corresponding guide ,
And as a demo, I suggest a code
Camera powered and off
In the direction of the view LED.
Download two networks: for persons finding
And the predictions of the head position ,
Use a USB camera and note
What code pin number 2 by default.
***
Dedicated to all those who are enthusiastic
Worked on our project all year.
Let everything accelerate in the coming,
OpenVINO on Raspberry - the same IoT!
import cv2 as cv from gpiozero import LED from math import cos, sin, pi winName = 'OpenVINO on Raspberry Pi' cv.namedWindow(winName, cv.WINDOW_NORMAL) faceDetectionNet = cv.dnn.readNet('face-detection-retail-0004.xml', 'face-detection-retail-0004.bin') headPoseNet = cv.dnn.readNet('head-pose-estimation-adas-0001.xml', 'head-pose-estimation-adas-0001.bin') faceDetectionNet.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD) headPoseNet.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD) cap = cv.VideoCapture(0) led = LED(2) led.on() while cv.waitKey(1) != 27: hasFrame, frame = cap.read() if not hasFrame: break frameHeight, frameWidth = frame.shape[0], frame.shape[1] # Detect faces on the image. blob = cv.dnn.blobFromImage(frame, size=(300, 300), ddepth=cv.CV_8U) faceDetectionNet.setInput(blob) detections = faceDetectionNet.forward() for detection in detections.reshape(-1, 7): confidence = float(detection[2]) if confidence > 0.5: xmin = int(detection[3] * frameWidth) ymin = int(detection[4] * frameHeight) xmax = int(detection[5] * frameWidth) ymax = int(detection[6] * frameHeight) xmax = max(1, min(xmax, frameWidth - 1)) ymax = max(1, min(ymax, frameHeight - 1)) xmin = max(0, min(xmin, xmax - 1)) ymin = max(0, min(ymin, ymax - 1)) # Run head pose estimation network. face = frame[ymin:ymax+1, xmin:xmax+1] blob = cv.dnn.blobFromImage(face, size=(60, 60), ddepth=cv.CV_8U) headPoseNet.setInput(blob) headPose = headPoseNet.forward(['angle_p_fc', 'angle_r_fc', 'angle_y_fc']) p, r, y = headPose[0][0], headPose[1][0], headPose[2][0] cos_r = cos(r * pi / 180) sin_r = sin(r * pi / 180) sin_y = sin(y * pi / 180) cos_y = cos(y * pi / 180) sin_p = sin(p * pi / 180) cos_p = cos(p * pi / 180) x = int((xmin + xmax) / 2) y = int((ymin + ymax) / 2) # center to right cv.line(frame, (x,y), (x+int(50*(cos_r*cos_y+sin_y*sin_p*sin_r)), y+int(50*cos_p*sin_r)), (0, 0, 255), thickness=3) # center to top cv.line(frame, (x, y), (x+int(50*(cos_r*sin_y*sin_p+cos_y*sin_r)), y-int(50*cos_p*cos_r)), (0, 255, 0), thickness=3) # center to forward cv.line(frame, (x, y), (x + int(50*sin_y*cos_p), y + int(50*sin_p)), (255, 0, 0), thickness=3) cv.rectangle(frame, (xmin, ymin), (xmax, ymax), (0, 255, 255)) if abs(cos_y * cos_p) > 0.9: cv.putText(frame, 'FORWARD', (0, 30), cv.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), thickness=2) led.off() else: led.on() cv.imshow(winName, frame)
Source: https://habr.com/ru/post/434238/
All Articles