Repository navigation
Expand file tree
/
Copy pathtelemed_class.py
More file actions
98 lines (77 loc) · 3.54 KB
/
Copy pathtelemed_class.py
File metadata and controls
98 lines (77 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Scanner Libraries
import sys
import ctypes
from ctypes import *
import numpy as np
import cv2
# Change these values to define the width and depth picked up by the ultrasound system
IMAGE_HEIGHT = 512
IMAGE_WIDTH = 512
class TelemedObject:
"""
Class for Interfacing directly with the Telemed ArtUS.
A TelemedObject stores a pointer to ultrasound sensor readings from a specified probe,
the resolution of that probe, and the index of the probe (For the ArtUS probeIndex = 0 is bottom scanner, probeIndex = 1 is top scanner)
"""
def __init__(self):
# current height and width values defined in our .dll (may be different for different users)
self.w = IMAGE_HEIGHT
self.h = IMAGE_WIDTH
# Load the C library for the Telemed
# Change the file path below to match your system, but it most point to the usgfw2wrapper.dll
PATH_TO_DLL = r".\telemed_dll\usgfw2wrapper_C++_sources\usgfw2wrapper\x64\Debug\usgfw2wrapper.dll"
self.usgfw2 = cdll.LoadLibrary(PATH_TO_DLL)
if self.usgfw2.init_ultrasound_usgfw2()<0:
print(f"[Error]: Usgfw2 library not initialized.")
sys.exit()
result = self.usgfw2.find_connected_probe()
if result < 0:
print(f"[Error]: Find Connected Probe Error -> {result}")
sys.exit()
result = self.usgfw2.data_view_function()
if result < 0:
print(f"[Error]: Data view function Error -> {result}")
sys.exit()
result = self.usgfw2.mixer_control_function(0, 0, self.w, self.h, 0, 0, 0)
if result < 0:
print(f"[Error]: Mixer Control function Error -> {result}")
sys.exit()
def setup_scanner(self, probeIndex = 0):
"""
Sets up all the needed data for an ultrasound probe.
"""
res_X = ctypes.c_float(0.0)
res_Y = ctypes.c_float(0.0)
self.usgfw2.get_resolution(probeIndex, pointer(res_X), pointer(res_Y))
resolutions = (res_X.value, res_Y.value) # this finds and determines the resolution of the connected probe
p_array = (ctypes.c_uint * (self.w * self.h * 4))() # pointer array that stores ultrasound data, 4 channels!
return {
"p_array": p_array,
"resolutions": resolutions,
"probeIndex": probeIndex
}
def update_scanner(self, probe):
"""
Gets the next ultrasound image returned from the specified probe.
"""
res_X = ctypes.c_float(0.0)
res_Y = ctypes.c_float(0.0)
self.usgfw2.return_pixel_values(probe["probeIndex"], ctypes.pointer(probe["p_array"])) # pulling pixel values from the probe
buffer_copy = np.copy(np.frombuffer(probe["p_array"], np.uint))
reshaped_array = np.reshape(buffer_copy, (self.w, self.h // 2, 4))
image_matrix = reshaped_array[:,:,3].astype(np.uint8).copy()
image_matrix = cv2.medianBlur(image_matrix,7) # applying a blur to help with optical flow tracking
# Check resolution changes
self.usgfw2.get_resolution(probe["probeIndex"], pointer(res_X), pointer(res_Y))
if (res_X.value, res_Y.value) != probe["resolutions"]:
probe["resolutions"] = (res_X.value, res_Y.value)
return(image_matrix)
def end_scanner(self):
"""
Safely ends the scanning loop on the Telemed device.
"""
self.usgfw2.Stop_ultrasound_scanning()
self.usgfw2.Close_and_release()
return()