Skip to content

Commit 7313cc2

Browse files
committed
Upload required files
1 parent 83bf9bf commit 7313cc2

File tree

9 files changed

+417
-122
lines changed

9 files changed

+417
-122
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

pipeline-1/pipeline-1-main.py renamed to pipeline-1-main.py

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,40 @@
77
import cv2
88
from time import perf_counter, sleep
99
import os
10+
import tensorflow as tf
11+
import numpy as np
12+
from time import perf_counter
13+
import easyocr
14+
from ultralytics import YOLO
15+
from extract_information import extract_information_from_image
1016

1117
"""
1218
TODO:
1319
- we have to add two options
1420
[] - if only one image is given
1521
[done] - if we have to do it using feed from webcam
1622
- the pipeline gets stopped if we get more number of points after segmentation add that.
17-
1823
"""
1924

20-
2125
def initialize() -> None:
2226
"""
2327
This function initializes the constant factors of the pipeline like the yolo model, logging, and to create a directory to store the images
2428
"""
2529
format = "%(asctime)s [%(levelname)s] %(message)s"
2630
logging.basicConfig(
27-
level=logging.DEBUG,
31+
level=logging.ERROR,
2832
format=format,
2933
handlers=[logging.FileHandler("pipeline-1.log")],
3034
)
3135

32-
from ultralytics import YOLO
33-
34-
logging.log(logging.INFO, "Loading the YOLO model")
35-
global model
36-
model = YOLO("./model_yolo/best.pt")
37-
logging.log(logging.INFO, "Loaded the YOLO model")
36+
try:
37+
global model
38+
model = YOLO(model="./model_yolo/best.pt")
39+
logging.log(logging.INFO, "Loaded the YOLO model")
40+
except Exception as e:
41+
logging.log(logging.ERROR, e)
42+
logging.log(logging.ERROR, "Unable to load the YOLO model")
43+
exit(1)
3844

3945
logging.log(level=logging.INFO, msg="Creating the directory structure!")
4046
if not os.path.exists("images"):
@@ -44,6 +50,54 @@ def initialize() -> None:
4450
logging.log(level=logging.DEBUG, msg=f"{os.getcwd()}")
4551
logging.log(level=logging.INFO, msg="Created the directory structure!")
4652

53+
global reader
54+
reader = easyocr.Reader(["en"])
55+
56+
global coordinates_dict
57+
coordinates_dict = {
58+
"2": {
59+
"heart_rate": [949, 58, 1082, 151],
60+
"map": [1209, 158, 1350, 230],
61+
"spo2": [942, 318, 1085, 423],
62+
"rr": [929, 420, 948, 530],
63+
"dbp": [1099, 159, 1178, 221],
64+
"sbp": [946, 162, 1058, 217],
65+
},
66+
"3": {
67+
"rr": [915, 532, 1247, 712],
68+
"dbp": [303, 562, 536, 750],
69+
"spo2": [937, 260, 1246, 445],
70+
"map": [563, 599, 801, 770],
71+
"heart_rate": [880, 41, 1240, 207],
72+
"sbp": [70, 550, 276, 765],
73+
},
74+
"4": {
75+
"map": [141, 378, 272, 447],
76+
"heart_rate": [71, 80, 415, 242],
77+
"spo2": [93, 469, 424, 605],
78+
"sbp": [18, 310, 195, 405],
79+
"rr": [303, 646, 452, 726],
80+
"dbp": [257, 317, 442, 398],
81+
},
82+
"1": {
83+
"map": [899, 581, 1108, 690],
84+
"heart_rate": [0, 0, 281, 185],
85+
"sbp": [681, 394, 955, 574],
86+
"spo2": [7, 345, 358, 573],
87+
"rr": [678, 48, 998, 249],
88+
"dbp": [1058, 386, 1252, 581],
89+
},
90+
}
91+
92+
try:
93+
global classifier_model
94+
classifier_model = tf.keras.models.load_model(filepath="./classifier/model.h5")
95+
logging.log(logging.INFO, "Loaded the classifier model")
96+
except Exception as e:
97+
logging.log(logging.ERROR, e)
98+
logging.log(logging.ERROR, "Unable to load the classifier model")
99+
exit(1)
100+
47101
sleep(2)
48102

49103

@@ -73,6 +127,33 @@ def get_segmentation(img_path: str):
73127
return None
74128

75129

130+
def get_monitor_type(img):
131+
"""
132+
This function returns the type of the image
133+
Input: img: np.ndarray
134+
Output: type: str
135+
"""
136+
137+
img = np.array(img).astype(dtype="float32") / 255.0
138+
img = cv2.resize(img, (224, 224))
139+
x = np.expand_dims(img, axis=0)
140+
k = None
141+
if classifier_model is not None:
142+
preds = classifier_model.predict(x)
143+
k = np.argmax(preds)
144+
145+
if k == 0:
146+
return "1"
147+
elif k == 1:
148+
return "2"
149+
elif k == 2:
150+
return "3"
151+
elif k == 3:
152+
return "4"
153+
else:
154+
return None
155+
156+
76157
def main() -> None:
77158
img_queue = queue.Queue()
78159

@@ -88,8 +169,19 @@ def main() -> None:
88169
if not img_queue.empty():
89170
img_path = img_queue.get()
90171
logging.log(level=logging.DEBUG, msg=f"{img_queue.qsize()}")
91-
logging.log(level=logging.DEBUG, msg=f"Got the image path: {img_path}")
92172
segmentation = get_segmentation(img_path=img_path)
173+
174+
if segmentation is None or segmentation.shape[0] != 4:
175+
logging.log(
176+
level=logging.WARNING,
177+
msg="segmentation is either None or segmentataion is not apt.",
178+
)
179+
continue
180+
181+
"""
182+
TODO: check if the segmentation length is strictly equal to 4 or not if not then skip for now and create alert...
183+
"""
184+
93185
logging.log(
94186
level=logging.INFO, msg="Got the segmentation mask of the image"
95187
)
@@ -101,6 +193,16 @@ def main() -> None:
101193
)
102194
logging.log(level=logging.INFO, msg="Got the processed image")
103195

196+
monitor_type = get_monitor_type(processed_image)
197+
print(monitor_type)
198+
print(
199+
extract_information_from_image(
200+
img=processed_image,
201+
coordinates_dict=coordinates_dict[monitor_type],
202+
kwargs={"reader": reader},
203+
)
204+
)
205+
104206
try:
105207
if not os.path.exists("processed_images"):
106208
logging.log(

pipeline-1/capture_img.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

readme.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Cloudphysician
2+
Read [this document](./static/project-proposal.pdf) for the motivation to make this project.
3+
4+
## Dependencies
5+
- **Python3**: Ensure that you have Python 3 installed on your system. You can download and install Python 3 from the official Python website: https://www.python.org.
6+
- **pip**: pip is the package installer for Python. It is usually installed by default when you install Python. However, make sure you have pip installed and it is up to date. You can check the version of pip by running the following command:
7+
```
8+
pip --version
9+
```
10+
## Installation
11+
To install and use Cloudphysician, follow the steps given below:
12+
- Fork the Cloudphysician repository by clicking the "Fork" button at the top right corner of the repository page. This will create a copy of the repository under your GitHub account.
13+
- Clone the forked repository to your local machine:
14+
```
15+
git clone https://github.com/{YOUR-USERNAME}/Cloudphysician
16+
```
17+
- Navigate to the project directory:
18+
```
19+
cd Cloudphysician
20+
```
21+
- Install the necessary Python packages by running the following command:
22+
```
23+
pip install -r requirements.txt
24+
```
25+
(NOTE: It is recommended to install these requirements in a new python environment)
26+
27+
## How to use?
28+
29+
Follow the steps given below:
30+
31+
32+
33+
## Output
34+
### Input Image
35+
![sample_image.jpeg](./static/sample_image.jpeg)
36+
37+
### Result
38+
![results.jpeg](./static/results.jpeg)
39+
40+
## Future Developement
41+
42+
43+
## Contributions
44+
Contributions to Cloudphysician are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository.
45+
46+
## Author
47+
[Abhishek Singh Kushwaha](https://github.com/ASK-03)
48+
49+
[Kriti Gupta](https://github.com/Kriti1106)
50+
51+
[Bhavik Shangari](https://github.com/BhavikShangari)

0 commit comments

Comments
 (0)