Skip to content
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

Feature/276 new script file for testing framework #238

Open
wants to merge 78 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
d2d27d3
276 Add new script, fixes to some bugs found and changes to current s…
rolandoquesada Oct 22, 2024
2f019df
276 Apply format in Python files
rolandoquesada Oct 22, 2024
7feb16d
276 Fix compilation error when merging the file
rolandoquesada Oct 22, 2024
9472fff
Merge branch 'feature/276_new_script_file_for_testing_01' of https://…
rolandoquesada Oct 22, 2024
88dde27
276 Update some tests and run_all_tests.py file
rolandoquesada Oct 23, 2024
6681c88
276 Fix code scanning alert no. 18
rolandoquesada Oct 23, 2024
559b9e1
276 Fix code scanning alert
rolandoquesada Oct 23, 2024
ac1fa70
276 Enabled the option of printing out the log files generated by the…
rolandoquesada Oct 24, 2024
a7c293e
276 Attempt to print out the logs created by the testing process
rolandoquesada Oct 25, 2024
fa3d680
276 Another attempt to print out the contents of the logs
rolandoquesada Oct 25, 2024
0269c4d
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Oct 25, 2024
03d1c72
Update CI.yml
michaelbeale-IL Oct 25, 2024
c5fe9d4
Merge pull request #242 from IntelLabs/CI-Fix
michaelbeale-IL Oct 25, 2024
b75e2e6
276 Add one new line just to trigger the CI/CD process
rolandoquesada Oct 25, 2024
c8fb9b7
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Oct 30, 2024
d1c8429
276 Attempt to print out the logs in case of any errors
rolandoquesada Oct 31, 2024
4e49638
276 Add new step in the _CI_coverage.yml file
rolandoquesada Oct 31, 2024
199c599
276 Attempt to print the logs of the testing
rolandoquesada Nov 1, 2024
548ac77
276 Display the python version
rolandoquesada Nov 1, 2024
98bf2f8
276 Add import skvideo.io to the function files
rolandoquesada Nov 2, 2024
a9646dc
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Nov 4, 2024
5a3b0ee
276 Attempt to reload the skvideo module during the testing
rolandoquesada Nov 4, 2024
0f5e7f5
276 Reload the cv2 library for fixing issue during the testing
rolandoquesada Nov 5, 2024
db987b5
276 Python 3.12 version used in the run_all_tests.py file
rolandoquesada Nov 5, 2024
7060ffb
276 Attempt to fix the issue related to the mp4 encoder missing
rolandoquesada Nov 6, 2024
876878f
276 Show error message in QueryHandler.CustomFunctionNoProcess test
rolandoquesada Nov 7, 2024
8e00db8
276 Remove QueryHandler.CustomFunctionNoProcess test
rolandoquesada Nov 13, 2024
263d2d5
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Nov 13, 2024
a752da1
276 Fix run_all_tests.py file to retrieve the coverage for the Python…
rolandoquesada Nov 14, 2024
c203d72
Automated updates: Format and/or coverage
sys-vdms Nov 14, 2024
3b41e70
276 Bring back the execution of the E2E tests for Neo4J
rolandoquesada Nov 14, 2024
fca8990
Merge branch 'feature/276_new_script_file_for_testing_01' of https://…
rolandoquesada Nov 14, 2024
f0f329c
276 Fix a compilation error due to a missing include in utils.h file
rolandoquesada Nov 14, 2024
dee7103
Automated updates: Format and/or coverage
sys-vdms Nov 14, 2024
b2b01c6
276 Remove any calls to CustomVCL class
rolandoquesada Nov 21, 2024
82af33d
Automated updates: Format and/or coverage
sys-vdms Nov 21, 2024
59f050e
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Feb 11, 2025
2b39aae
276 Add debug message for checking the call to "cleanup_query()" func…
rolandoquesada Feb 19, 2025
846515a
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Feb 21, 2025
d5e21f4
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Feb 22, 2025
5cf2827
276 Fix compilation errors after merge commit
rolandoquesada Feb 22, 2025
17e9c02
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Feb 22, 2025
02ebc64
276 Fix errors reported during the pre-commit stage
rolandoquesada Feb 24, 2025
892e32c
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Feb 24, 2025
6c5437c
276 Add debug messages to check where cleanup_error() is called
rolandoquesada Feb 26, 2025
84d8ac0
Merge branch 'develop' into feature/276_new_script_file_for_testing_01
rolandoquesada Mar 5, 2025
2831473
276 Apply linting and formatting fixes
rolandoquesada Mar 6, 2025
9070e86
276 Update older scripts to delete temporary database directories
rolandoquesada Mar 6, 2025
e6715bc
276 Add new tests cases
rolandoquesada Mar 6, 2025
2bdc26f
276 Remove typo
rolandoquesada Mar 6, 2025
c42816b
Automated coverage update
github-actions[bot] Mar 6, 2025
880fade
276 Removing debugging messages
rolandoquesada Mar 14, 2025
e0396fe
276 Remove commented line
rolandoquesada Mar 15, 2025
b76b124
276 More fixes according to feedback received from PR
rolandoquesada Mar 15, 2025
d62586c
Automated coverage update
github-actions[bot] Mar 15, 2025
4a51371
276 Move the logic to set the haarcascade_frontalface_default_path va…
rolandoquesada Mar 17, 2025
62fe4c7
276 Update the README files
rolandoquesada Mar 17, 2025
f2634ac
276 Remove the duplicated files of the haarcascade_frontalface_defaul…
rolandoquesada Mar 17, 2025
c7c677f
Merge branch 'feature/276_new_script_file_for_testing_01' of https://…
rolandoquesada Mar 17, 2025
ef4fc01
276 Add resources dir to the repo
rolandoquesada Mar 17, 2025
dc5184e
276 Remove hardcoded pid to the tests in TestScript
rolandoquesada Mar 17, 2025
c4c44ed
276 Fix error in the path to the xml required by UDF tests
rolandoquesada Mar 18, 2025
4e7129c
276 Remove in Server the lines related to delete the DB
rolandoquesada Mar 18, 2025
9059c3b
276 Fix typo in the path to the file
rolandoquesada Mar 18, 2025
6127ca2
276 Add more information to the error messages
rolandoquesada Mar 18, 2025
76f13bd
276 Fix path to file
rolandoquesada Mar 18, 2025
6bf19a4
276 Fix errors related to the path of the files
rolandoquesada Mar 18, 2025
b81c904
276 Add resources dir to the container
rolandoquesada Mar 18, 2025
f21859b
276 Update the path to the resource file
rolandoquesada Mar 20, 2025
1add1f7
276 Fix bug related to the paths which were not being found correctly
rolandoquesada Mar 25, 2025
19ee20f
Automated coverage update
github-actions[bot] Mar 25, 2025
3f6dd8f
276 Remove hardcoded values for the mocked pids in TestScript.py file
rolandoquesada Mar 25, 2025
4e506d0
Merge branch 'feature/276_new_script_file_for_testing_01' of https://…
rolandoquesada Mar 25, 2025
de9a709
276 Bring back the use of the previous library in the caption.py files
rolandoquesada Mar 26, 2025
d840731
276 Fix some wrong paths in one of the CI/CD files
rolandoquesada Mar 26, 2025
da64dfa
Revert "276 Bring back the use of the previous library in the caption…
rolandoquesada Mar 27, 2025
0f74054
276 Update the code in caption.py files for using the fps from the in…
rolandoquesada Mar 27, 2025
4cdcf4f
276 Update the caption.py files
rolandoquesada Mar 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions .github/coverage/cpp.develop.coverage_report.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/coverage/cpp.develop.coverage_value.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
64.2822
64.2075
17 changes: 9 additions & 8 deletions .github/scripts/run_coverage_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

cd /vdms/tests

# Run Local C++ PMGD Based Tests
chmod +x run_tests.sh
echo 'Running run_tests.sh script'
./run_tests.sh

# Run S3 C++ PMGD Based Tests
echo 'Checking for the available disk space due MinIO requires at least 1gb free'
df -h
chmod +x run_aws_tests.sh
echo 'Running run_aws_tests.sh script'
./run_aws_tests.sh -u ${AWS_ACCESS_KEY_ID} -p ${AWS_SECRET_ACCESS_KEY}

chmod +x ./run_all_tests.py

echo 'Running run_all_tests.py script for remote C++ tests (-t=ru)'
python ./run_all_tests.py -t=ru -k -u ${AWS_ACCESS_KEY_ID} -p ${AWS_SECRET_ACCESS_KEY}

echo 'Running run_all_tests script for C++ tests (-t=ut)'
python ./run_all_tests.py -t=ut -k

echo 'Getting the coverage for C++'
# Obtain Coverage
gcovr --root /vdms \
-e /vdms/src/pmgd -e /vdms/build -e /vdms/distributed -e /vdms/tests \
Expand Down
27 changes: 22 additions & 5 deletions .github/scripts/run_coverage_py.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/bin/bash -e

cd /vdms/tests/python
cd /vdms/tests
chmod +x ./run_all_tests.py
chmod +x ./TestScript.py

./run_python_tests.sh
./run_python_aws_tests.sh -u ${AWS_ACCESS_KEY_ID} -p ${AWS_SECRET_ACCESS_KEY}
python -m coverage report -m 2>&1 | tee /vdms/tests/coverage_report/python.new.coverage_report.txt
python -m coverage xml -o /vdms/tests/coverage_report/python.new.coverage_report.xml
# Check .coverage file doesn't exist
if [ -f './.coverage' ]; then
echo ".coverage exists."
rm ./.coverage
echo ".coverage deleted."
fi

echo 'Running run_all_tests script for Python tests (-t=pt)'
python3 ./run_all_tests.py -t=pt -k

echo 'Running run_all_tests script for Remote Python tests (-t=rp)'
python3 ./run_all_tests.py -t=rp -k -u=${AWS_ACCESS_KEY_ID} -p=${AWS_SECRET_ACCESS_KEY}

echo 'Running the tests included in TestScript.py file'
# Append the coverage results to the ones obtained from running run_all_tests.py
python3 -m coverage run -a --omit="./run_all_tests.py,./TestScript.py" -m unittest discover --pattern=TestScript.py -v

python3 -m coverage report -m 2>&1 | tee /vdms/tests/coverage_report/python.new.coverage_report.txt
python3 -m coverage xml -o /vdms/tests/coverage_report/python.new.coverage_report.xml

echo "DONE"

Expand Down
52 changes: 44 additions & 8 deletions .github/workflows/_CI_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ jobs:
echo "VDMS_TAG=${VDMS_TAG_STR}" >> $GITHUB_OUTPUT

# Commands for neo4j tests
COMMON_ARGS="-n ${{ secrets.NEO4J_USER }} -w ${{ secrets.NEO4J_PASS }} -v ${{ env.NEO_TEST_PORT}}"
S3_ARGS="-a ${{ env.AWS_API_PORT }} -c ${{ env.AWS_CONSOLE_PORT}} -u ${{ secrets.AWS_ACCESS_KEY_ID }} -p ${{ secrets.AWS_SECRET_ACCESS_KEY }}"
COMMON_ARGS="--neo4j_username ${{ secrets.NEO4J_USER }} --neo4j_password ${{ secrets.NEO4J_PASS }} --neo4j_port ${{ env.NEO_TEST_PORT }}"
S3_ARGS="--minio_port ${{ env.AWS_API_PORT }} --minio_console_port ${{ env.AWS_CONSOLE_PORT }} -u ${{ secrets.AWS_ACCESS_KEY_ID }} -p ${{ secrets.AWS_SECRET_ACCESS_KEY }}"

CMD_STR_e2e_str="./run_neo4j_tests.sh -t Neo4JE2ETest ${S3_ARGS} ${COMMON_ARGS} -e neo4j://neo4j:${{ env.NEO_TEST_PORT}}"
CMD_STR_e2e_str="./run_all_tests.py --type_of_test neo --test_name 'Neo4JE2ETest.*' ${S3_ARGS} ${COMMON_ARGS} --neo4j_endpoint neo4j://neo4j:${{ env.NEO_TEST_PORT}}"
echo "CMD_STR_e2e=${CMD_STR_e2e_str}" >> $GITHUB_OUTPUT

CMD_STR_OpsIO_str="./run_neo4j_tests.sh -t OpsIOCoordinatorTest ${S3_ARGS} ${COMMON_ARGS} -e neo4j://neo4j:${{ env.NEO_TEST_PORT}}"
CMD_STR_OpsIO_str="./run_all_tests.py --type_of_test neo --test_name 'OpsIOCoordinatorTest.*' ${S3_ARGS} ${COMMON_ARGS} --neo4j_endpoint neo4j://neo4j:${{ env.NEO_TEST_PORT }}"
echo "CMD_STR_OpsIO=${CMD_STR_OpsIO_str}" >> $GITHUB_OUTPUT

CMD_STR_bkend_str="./run_neo4j_tests.sh -t Neo4jBackendTest ${COMMON_ARGS} -e neo4j://neo4j:${{ env.NEO_TEST_PORT}}"
CMD_STR_bkend_str="./run_all_tests.py --type_of_test neo --test_name 'Neo4jBackendTest.*' ${COMMON_ARGS} --neo4j_endpoint neo4j://neo4j:${{ env.NEO_TEST_PORT }}"
echo "CMD_STR_bkend=${CMD_STR_bkend_str}" >> $GITHUB_OUTPUT

- name: Run Neo4J Tests
Expand All @@ -183,7 +183,7 @@ jobs:

# E2E Test
echo "${{ env.CMD_STR_e2e }}"
docker exec -w /vdms/tests ${{ env.SOURCE_CONTAINER_NAME }} bash -c "${{ env.CMD_STR_e2e }}"
docker exec -w /vdms/tests ${{ env.SOURCE_CONTAINER_NAME }} bash -c "python ${{ env.CMD_STR_e2e }}"
docker kill ${{ env.NEO4J_CONTAINER_NAME }} || true
sleep 15

Expand All @@ -203,7 +203,7 @@ jobs:

# Ops IO Test
echo "${{ env.CMD_STR_OpsIO }}"
docker exec -w /vdms/tests ${{ env.SOURCE_CONTAINER_NAME }} bash -c "${{ env.CMD_STR_OpsIO }}"
docker exec -w /vdms/tests ${{ env.SOURCE_CONTAINER_NAME }} bash -c "python ${{ env.CMD_STR_OpsIO }}"
docker kill ${{ env.NEO4J_CONTAINER_NAME }} || true
sleep 15

Expand All @@ -226,7 +226,43 @@ jobs:
docker cp ${{ env.SOURCE_CONTAINER_NAME }}:/vdms/tests/coverage_report/python.new.coverage_value.txt ${GITHUB_WORKSPACE}/.github/coverage/python.new.coverage_value.txt || true
echo "coverage_value_py=$(cat ${GITHUB_WORKSPACE}/.github/coverage/python.new.coverage_value.txt)" >> $GITHUB_ENV
echo "pr_dev_value_py=$(cat ${GITHUB_WORKSPACE}/.github/coverage/python.old-develop.coverage_value.txt)" >> $GITHUB_ENV

- name: Print out the logs
shell: bash
id: print_out_logs
if: ${{ always() }}
run: |
echo "print pip version"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} pip -V || true
echo "Python version"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} python --version || true
echo "Python3 version"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} python3 --version || true
echo "Print out the logs"
echo "tests_stderr_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/tests_stderr_log.log || true
echo "tests_stdout_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/tests_stdout_log.log || true
echo "tls_stderr_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/tls_stderr_log.log || true
echo "tls_stdout_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/tls_stdout_log.log || true
echo "udf_local_stderr_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/udf_local_stderr_log.log || true
echo "udf_local_stdout_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/udf_local_stdout_log.log || true
echo "udf_server_stderr_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/udf_server_stderr_log.log || true
echo "udf_server_stdout_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/udf_server_stdout_log.log || true
echo "vdms_stderr_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/vdms_stderr_log.log || true
echo "vdms_stdout_log:"
docker exec ${{ env.SOURCE_CONTAINER_NAME }} cat /vdms/tests/tests_output_dir/vdms_stdout_log.log || true
echo "End of Print out the logs..."
- name: Docker Compose down
shell: bash
id: docker_compose_down
run: |
# Stops containers and removes containers, networks, volumes, and images
cd ${GITHUB_WORKSPACE}/.github/scripts
docker compose down
Expand Down
35 changes: 0 additions & 35 deletions include/vcl/CustomVCL.h

This file was deleted.

4 changes: 3 additions & 1 deletion include/vcl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2017 Intel Corporation
* @copyright Copyright (c) 2024 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -31,6 +31,8 @@

#include <time.h>

#include <cstdint>
#include <string>
#include <vector>

namespace VCL {
Expand Down
37 changes: 27 additions & 10 deletions remote_function/functions/caption.py
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import cv2
import skvideo.io
import uuid
import os
import sys

DEBUG_MODE = False

def run(ipfilename, format, options):
opfilename = "tmpfile" + uuid.uuid1().hex + "." + str(format)
print(opfilename)

def run(ipfilename, format, options, tmp_dir_path, functions_path):
if DEBUG_MODE:
print("Temporary path:", tmp_dir_path, file=sys.stderr)
print("Functions path:", functions_path, file=sys.stderr)
print("options:", options, file=sys.stderr)
print("format:", format, file=sys.stderr)
print("ipfilename", ipfilename, file=sys.stderr)
opfilename = os.path.join(
tmp_dir_path, "tmpfile" + uuid.uuid1().hex + "." + str(format)
)
if DEBUG_MODE:
print("opfilename:", opfilename, file=sys.stderr)
vs = cv2.VideoCapture(ipfilename)
frame_width = int(vs.get(3))
frame_height = int(vs.get(4))

video = cv2.VideoWriter(
opfilename, cv2.VideoWriter_fourcc(*"XVID"), 30, (frame_width, frame_height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm that having XVID fourcc will not cause issues with other file formats such as mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Rohit, could you please give me more details about how to test that? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check using other file formats that use different codecs. For example, mp4 uses MP4V.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rv355, I tested the new changes with mov, avi and mp4 files by using mp4v. All of them worked fine and also the current tests passed successfully. BTW, when I ran the tests for XVID, the new video files were not compatible with the default video players in Windows OS

)

video = skvideo.io.FFmpegWriter(opfilename, {"-pix_fmt": "bgr24"})
print(options)
if DEBUG_MODE:
print(options, file=sys.stderr)

while True:
(grabbed, frame) = vs.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)
video.release()

return opfilename
return opfilename, None
39 changes: 31 additions & 8 deletions remote_function/functions/facedetect.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import cv2
import os
import sys

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"
)
DEBUG_MODE = False


def run(ipfilename, format, options):
global face_cascade
def run(ipfilename, format, options, tmp_dir_path, functions_path):
if DEBUG_MODE:
print("Temporary path:", tmp_dir_path, file=sys.stderr)
print("Functions path:", functions_path, file=sys.stderr)
print("options:", options, file=sys.stderr)
print("format:", format, file=sys.stderr)
print("ipfilename", ipfilename, file=sys.stderr)

haarcascade_frontalface_default_path = os.path.join(
functions_path, "files/haarcascade_frontalface_default.xml"
)

if not os.path.exists(haarcascade_frontalface_default_path):
raise Exception(f"{haarcascade_frontalface_default_path}: path is invalid")

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
haarcascade_frontalface_default_path
)

if DEBUG_MODE:
print("Facedetect: ipfilename", ipfilename)
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)
Expand All @@ -17,4 +40,4 @@ def run(ipfilename, format, options):
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
46 changes: 39 additions & 7 deletions remote_function/functions/metadata.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import cv2
import uuid
import json
import os
import sys

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"
)
DEBUG_MODE = False

face_cascade = None


def set_face_cascade(functions_path):
global face_cascade
haarcascade_frontalface_default_path = os.path.join(
functions_path, "files/haarcascade_frontalface_default.xml"
)

if not os.path.exists(haarcascade_frontalface_default_path):
raise Exception(f"{haarcascade_frontalface_default_path}: path is invalid")

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
haarcascade_frontalface_default_path
)


def facedetectbbox(frame):
Expand All @@ -16,7 +32,16 @@ def facedetectbbox(frame):
return faces


def run(ipfilename, format, options):
def run(ipfilename, format, options, tmp_dir_path, functions_path):
if DEBUG_MODE:
print("Temporary path:", tmp_dir_path, file=sys.stderr)
print("Functions path:", functions_path, file=sys.stderr)
print("options:", options, file=sys.stderr)
print("format:", format, file=sys.stderr)
print("ipfilename:", ipfilename, file=sys.stderr)

set_face_cascade(functions_path)

# Extract metadata for video files
if options["media_type"] == "video":
vs = cv2.VideoCapture(ipfilename)
Expand Down Expand Up @@ -69,13 +94,20 @@ def run(ipfilename, format, options):

response = {"opFile": ipfilename, "metadata": metadata}

jsonfile = "jsonfile" + uuid.uuid1().hex + ".json"
jsonfile = os.path.join(tmp_dir_path, "jsonfile" + uuid.uuid1().hex + ".json")
with open(jsonfile, "w") as f:
json.dump(response, f, indent=4)
return ipfilename, jsonfile
# Extract metadata for image files
else:
tdict = {}
if DEBUG_MODE:
print("Metadata: ipfilename=", ipfilename, file=sys.stderr)
if not os.path.exists(ipfilename):
raise Exception(
f"Metadata error: File ipfilename {ipfilename} does not exist"
)

img = cv2.imread(ipfilename)
if options["otype"] == "face":
faces = facedetectbbox(img)
Expand Down
Loading