-
Notifications
You must be signed in to change notification settings - Fork 33
Feature/276 new script file for testing framework #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d2d27d3
2f019df
7feb16d
9472fff
88dde27
6681c88
559b9e1
ac1fa70
a7c293e
fa3d680
0269c4d
03d1c72
c5fe9d4
b75e2e6
c8fb9b7
d1c8429
4e49638
199c599
548ac77
98bf2f8
a9646dc
5a3b0ee
0f5e7f5
db987b5
7060ffb
876878f
8e00db8
263d2d5
a752da1
c203d72
3b41e70
fca8990
f0f329c
dee7103
b2b01c6
82af33d
59f050e
2b39aae
846515a
d5e21f4
5cf2827
17e9c02
02ebc64
892e32c
6c5437c
84d8ac0
2831473
9070e86
e6715bc
2bdc26f
c42816b
880fade
e0396fe
b76b124
d62586c
4a51371
62fe4c7
f2634ac
c7c677f
ef4fc01
dc5184e
c4c44ed
4e7129c
9059c3b
6127ca2
76f13bd
6bf19a4
b81c904
f21859b
1add1f7
19ee20f
3f6dd8f
4e506d0
de9a709
d840731
da64dfa
0f74054
4cdcf4f
df4d0ce
70e065b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
64.2822 | ||
64.2075 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ source venv/bin/activate | |
python3 -m pip install pip --upgrade | ||
python3 -m pip install wheel | ||
python3 -m pip install -r requirements.txt | ||
python3 udf_server.py <port_number> | ||
python3 udf_server.py <port_number> [path_tmp_dir] | ||
``` | ||
|
||
## Client Query | ||
|
@@ -78,15 +78,14 @@ We now provide an example to add a new operation `cardetect` as a remote operati | |
~/ | ||
|__remote_function | ||
|__functions | ||
| |__files | ||
| | |__haarcascade_frontalface_default.xml | ||
| |__facedetect.py | ||
|__README.md | ||
|__requirements.txt | ||
|__udf_server.py | ||
``` | ||
2. Download/Copy the `cars.xml` file to the `~/remote_function/functions/files`. | ||
3. Create the `cardetect.py` file in `~/remote_function/functions`. | ||
2. Copy the `resources` directory (located at the root of the repo) next to the `remote_function` directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rv355 I added this documentation to the README.md file so the user can know that the resources directory (it includes the _haarcascade_frontalface_default.xml file) needs to be copied to the required location. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cars.xml is used in the example code of the README. Please ensure that the resource files are the same throughout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @rv355 Please correct me if I am wrong. If Cars.xml file is provided, then the resources folder should not be included as part of the documentation in the README.md file because that folder contains the haarcascade_frontalface_default.xml file which for this case is not needed anymore, am I right? |
||
3. Download/Copy the `cars.xml` file to the `~/remote_function/functions/files`. | ||
4. Create the `cardetect.py` file in `~/remote_function/functions`. | ||
``` | ||
import time | ||
import cv2 | ||
|
@@ -113,17 +112,18 @@ def run(ipfilename, format, options): | |
|__remote_function | ||
|__functions | ||
| |__files | ||
| | |__haarcascade_frontalface_default.xml | ||
| | |__cars.xml | ||
| |__facedetect.py | ||
| |__cardetect.py | ||
|__README.md | ||
|__requirements.txt | ||
|__udf_server.py | ||
|__resources | ||
|__haarcascade_frontalface_default.xml | ||
``` | ||
5. Now start the remote server at port `5010` by running; | ||
5. Now start the remote server at port `5010` and specify the path to the temporary directory where the temporary files will be created (if you don't specify the directory then it will be created in the same path where the udf_server.py file is located at); | ||
``` | ||
python3 udf_server.py 5010 | ||
python3 udf_server.py 5010 [path_tmp_dir] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
``` | ||
6. Say VDMS has a database of car images that have the property `category` set as `cars`. Then you can run the `cardetect` operation on these images using the following query; | ||
``` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general I'd like to see (even if its just here in the PR) some explanations on why certain changes to core modules have been made as its way outside the initial scope of this task which was intended to be focused on breaking apart of better compartmentalizing of the testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The run_all_tests.py file was created for running the different type of tests (C++ and Python) written for VDMS. When that script was run for every type of tests, some of them failed and that caused the script was not able to be tested. To fix those small bugs, the corresponding fix was added as part of this PR. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
import cv2 | ||
import skvideo.io | ||
import uuid | ||
import os | ||
|
||
|
||
def run(ipfilename, format, options): | ||
opfilename = "tmpfile" + uuid.uuid1().hex + "." + str(format) | ||
print(opfilename) | ||
vs = cv2.VideoCapture(ipfilename) | ||
def run(ipfilename, format, options, tmp_dir_path): | ||
opfilename = os.path.join( | ||
tmp_dir_path, "tmpfile" + uuid.uuid1().hex + "." + str(format) | ||
) | ||
|
||
video = skvideo.io.FFmpegWriter(opfilename, {"-pix_fmt": "bgr24"}) | ||
print(options) | ||
vc = cv2.VideoCapture(ipfilename) | ||
frame_width = int(vc.get(cv2.CAP_PROP_FRAME_WIDTH)) | ||
frame_height = int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT)) | ||
video_fps = vc.get(cv2.CAP_PROP_FPS) | ||
|
||
video = cv2.VideoWriter( | ||
opfilename, | ||
cv2.VideoWriter_fourcc(*"mp4v"), | ||
video_fps, | ||
(frame_width, frame_height), | ||
) | ||
|
||
while True: | ||
(grabbed, frame) = vs.read() | ||
(grabbed, frame) = vc.read() | ||
if not grabbed: | ||
print("[INFO] no frame read from stream - exiting") | ||
video.close() | ||
# sys.exit(0) | ||
break | ||
|
||
label = options["text"] | ||
cv2.putText( | ||
frame, label, (10, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2 | ||
) | ||
|
||
video.writeFrame(frame) | ||
video.write(frame) | ||
vc.release() | ||
video.release() | ||
|
||
return opfilename | ||
return opfilename, None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import cv2 | ||
import os | ||
|
||
# Get the real directory where this Python file is | ||
currentDir = os.path.realpath(os.path.dirname(__file__)) | ||
|
||
haarcascade_frontalface_default_path = os.path.join( | ||
currentDir, "../../resources/haarcascade_frontalface_default.xml" | ||
) | ||
|
||
if not os.path.exists(haarcascade_frontalface_default_path): | ||
raise Exception( | ||
f"{haarcascade_frontalface_default_path}: path is invalid in facedetect for the remote function" | ||
) | ||
|
||
face_cascade = cv2.CascadeClassifier( | ||
# This file is available from OpenCV 'data' directory at | ||
# https://github.com/opencv/opencv/blob/4.x/data/haarcascades/haarcascade_frontalface_default.xml | ||
"functions/files/haarcascade_frontalface_default.xml" | ||
haarcascade_frontalface_default_path | ||
) | ||
|
||
|
||
def run(ipfilename, format, options): | ||
def run(ipfilename, format, options, tmp_dir_path): | ||
global face_cascade | ||
|
||
if not os.path.exists(ipfilename): | ||
raise Exception( | ||
f"Facedetect error: File ipfilename: {ipfilename} does not exist" | ||
) | ||
|
||
img = cv2.imread(ipfilename) | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
faces = face_cascade.detectMultiScale(gray, 1.1, 4) | ||
|
||
for x, y, w, h in faces: | ||
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) | ||
|
||
return img | ||
return img, None | ||
rolandoquesada marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rv355 I would like your opinion about this parameter that I added to the script file, I added it for letting the server know in which directory to create the temporary files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rolandoquesada Looks fine to me.