| English | Korean | Chinese | Japanese |
APIs: live video
Get a live image
You can obtain a live image using a channel number and sub-stream index.
The default sub-stream index is 0, which represents the primary stream.
(frame_image, frame_info) = get_image(ch_no, sub_idx=idx)
frame_image: numpy array of video image
· For the pixel format "BGR," the shape of the image is (height, width, 3).
frame_info: dictionary containing information of video image
· frame_info['timestamp']: Unix timestamp
· frame_info['timestamp_msec']: timestamp millisecond
· frame_info['message']: error message
You can also change the video output settings using the following APIs:
set_image_size(width, height): Set output video size. (Default: the original video size)
set_pixel_format("PIXEL_FORMAT"): Set output video format. You can choose from "RGB" / "BGR" / "0RGB" / "0BGR". (Default: "RGB")
live_video = vmspy.live_video()
if not live_video.init(address, port, access_id, access_pw):
print(live_video.get_error())
live_video.set_image_size(720, 480)
live_video.set_pixel_format("BGR")
(frame_image, frame_info) = live_video.get_image(1) # ch#1
Start live stream and receive video
You can start and stop a live stream using a channel number and sub-stream index.
The default sub-stream index is 0, which represents the primary stream.
start(ch_no, sub_idx=idx)
stop()
You can also change the video output with the following APIs.
set_image_size(width, height): Set output video size. (Default: the original video size)
set_pixel_format("PIXEL_FORMAT"): Set output video format. You can choose from "RGB" / "BGR" / "0RGB" / "0BGR". (Default: "RGB")
set_keyframe_only(Bool): Set whether to send only iFrames. (Default: False)
live_video.set_image_size(720, 480)
live_video.set_pixel_format("BGR")
live_video.set_keyframe_only(True)
live_video.start(1) # ch#1
# ...
live_video.stop()
Once started, you can receive video streams.
(frame_image, frame_info) = get_frame(): Receive video image and information.
frame_image: numpy array of video image
· For the pixel format "BGR," the shape of the image is (height, width, 3).
frame_info: dictionary containing information of video image
· frame_info['timestamp']: Unix timestamp
· frame_info['timestamp_msec']: timestamp millisecond
· frame_info['delay']: delayed seconds
· frame_info['buffer_count']: buffered frame count
· frame_info['message']: error message
live_video.start(1) # ch#1
while True:
(frame_image, frame_info) = live_video.get_frame()
if frame_image.size == 0:
print(frame_info['message'])
break
# Do analysis
# Reports detection results and events
live_video.stop()
Report detections and events
As an output of analysis, you can report detections and events back to the VMS server.
report_event(frame_info, x, y, w, h, duration, event_type_id, class_id, object_id)
x, y, w, h: location of the event, values are normalized by width and height respectively
duration: duration of the event in seconds
event_type_id: type Id of the event, you can define your custom Id starting from zero(0).
· Predefined system event Id: Motion(-1), Sensor(-2), Mobile(-3), Thermal(-4), Overparking(-5), Leakage(-6)
· Custom events can be configured in config.exe
class_id: class id of the event from AI detection model
object_id: object id of the event from AI detection model
The number of detection results is likely to be more than one. So you can input results multiple times and send them.
inputDetectionResult(x, y, w, h, class_id, object_id, confidence)
x, y, w, h: location of event, values are normalized by width and height respectively
class_id: class id of the event from AI detection model
object_id: object id of the event from AI detection model
confidence: confidence of inference
sendDetectionResults(frame_info): send the input results with frame information
frame_info: frame information from get_frame() (needed for timestamp)
for box in results[0].boxes:
xyxy = box.xyxy[0].tolist()
class_id = int(box.cls[0].item())
conf = box.conf[0].item()
x = xyxy[0]/640.0
y = xyxy[1]/640.0
w = (xyxy[2] - xyxy[0])/640.0
h = (xyxy[3] - xyxy[1])/640.0
live_video.inputDetectionResult(x, y, w, h, class_id=class_id, object_id=0, confidence=conf)
live_video.sendDetectionResults(frame_info)
Change the detection box
You have the option to modify the color, thickness, and caption of detection boxes.
set_detection_class(class_names): set the class name dictionary
set_detection_box(class_id, border_color, border_thickness): change the color and thickness of boxes
class_id: if not defined, defined color and thickness is applied to all classes. If defined, it will be only applied to the class.
border_color: This parameter determines the color of the box stroke. It can be specified using either a color name, such as "red," or a hexadecimal representation, like "#ffff0000."
· For a 6-digit format like "#ffffff," each set of two digits represents the Red, Green, and Blue (RGB) colors respectively.
· In an 8-digit format like "#ff000000," the first two digits indicate the alpha channel for transparency.
· In the case of a 3-digit format like "#fff," it is expanded to a 6-digit equivalent.
border_thickness: This parameter specifies the thickness of the border stroke, measured in pixels.
live_video.start("vms.address", 3300, 1, 0, "access_id", "access_pw")
class_names = {0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', ...}
live_video.set_detection_class(class_names)
live_video.set_detection_box(border_color="black", border_thickness=2)
live_video.set_detection_box(class_id=1, border_color="red")
live_video.set_detection_caption(show_object_id=False, show_class_name=True, show_confidence=False)
Draw Guide Shapes
You can draw guide shapes on the video. Please refer to the Draw Guide Shapes section for more details.
draw_line(x0, y0, x1, y1, border_thickness, border_color): draw a line
draw_rectangle(x, y, w, h, border_thickness, border_color): draw a rectangle
draw_ellipse(x, y, w, h, border_thickness, border_color): draw a ellipse
draw_polygon(point_array, border_thickness, border_color): draw a polygon
x, y, w, h, x0, y0, x1, y1: location of the event, values are normalized by width and height respectively
point_array: An array of tuples, where each tuple represents an x-y coordinate pair.
border_color: This parameter determines the color of the box stroke. It can be specified using either a color name, such as "red," or a hexadecimal representation, like "#ffff0000."
· For a 6-digit format like "#ffffff," each set of two digits represents the Red, Green, and Blue (RGB) colors respectively.
· In an 8-digit format like "#ff000000," the first two digits indicate the alpha channel for transparency.
· In the case of a 3-digit format like "#fff," it is expanded to a 6-digit equivalent.
border_thickness: This parameter specifies the thickness of the border stroke, measured in pixels.
vms_video.drawLine(0.342592, 0.273927, 0.177778, 0.003300,
border_thickness=4.0, border_color="#FF008000")
vms_video.drawRectangle(0.427783, 0.689699, 0.248139, 0.191559,
border_thickness=2.0, border_color="#FF0000FF")
vms_video.drawEllipse(0.427783, 0.689699, 0.248139, 0.191559,
border_thickness=2.0, border_color="#FF0000FF")
polygon_points = [(0.337037, 0.326733),
(0.412963, 0.323432),
(0.392593, 0.907591),
(0.161111, 0.904290)]
vms_video.drawPolygon(polygon_points, border_thickness=4.0, border_color="#FFFF0000")


