diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml deleted file mode 100644 index 567bca2..0000000 --- a/.github/workflows/clang-format.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: clang-format-checker - -on: push - -jobs: - check_merge: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Check if script returns 1 - run: | - set +x - ./ci/clang-format-checker.sh - exit_code=$? - - if [ $exit_code -eq 1 ]; then - exit 1 - else - echo "Merging is allowed." - fi \ No newline at end of file diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..2b11178 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5c54a65 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-xml +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: 'v17.0.6' # Use the sha / tag you want to point at + hooks: + - id: clang-format +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black diff --git a/README.md b/README.md index 2026649..5010821 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,17 @@ [![cpp-linter](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml) -# To Lint CPP -Make sure git-clang-format is installed with `npm install -g clang-format` -1. Call `clang-format.sh` under ci/ -2. `git add` and `git commit`! +## Installing pre-commit hooks -## To run +Install pre-commmit following the directions from [here](https://pre-commit.com/#install). If you're on a Mac with `homebrew`, the easiest way is `brew install pre-commit`. -`cd build` +Then, run `pre-commit install`. You only need to do this once. + +Now, pre-commit will run automatically when you make a commit, and will fix files for you. Make sure to add the changed files after pre-commit runs! + +## To run + +`cd build` `cmake ..` @@ -21,7 +24,7 @@ Make sure git-clang-format is installed with `npm install -g clang-format` - `cd` to `src/message/` -- Make a `.env` file with `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` set to your account SID and Auth Token +- Make a `.env` file with `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` set to your account SID and Auth Token - macOS: `brew tap twilio/brew && brew install twilio` diff --git a/ci/clang-format-checker.sh b/ci/clang-format-checker.sh deleted file mode 100755 index cea4b3c..0000000 --- a/ci/clang-format-checker.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -## Open all modified files in the current branch and run clang-format on them. -import subprocess - -# Get the list of modified files. from git -modified_files = subprocess.check_output( - "find src/ -iname *.h -o -iname *.cpp", - shell=True, -).splitlines() - -# convert to list of strings -modified_files = [f.decode("utf-8") for f in modified_files] - -for f in modified_files: - result = subprocess.run(["clang-format", "--dry-run", "--Werror", f]) - if result.returncode: - exit(1) \ No newline at end of file diff --git a/ci/clang-format.sh b/ci/clang-format.sh deleted file mode 100755 index d545317..0000000 --- a/ci/clang-format.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python3 - -## Open all modified files in the current branch and run clang-format on them. -import subprocess - -# Get the list of modified files. from git -#modified_files = subprocess.check_output( -# "{ git diff --name-only ; git diff --name-only --staged ; } | sort | uniq", -# shell=True, -#).splitlines() - -modified_files = subprocess.check_output( - "find ../src/ -iname *.h -o -iname *.cpp", - shell=True, -).splitlines() - -# convert to list of strings -modified_files = [f.decode("utf-8") for f in modified_files] - -for f in modified_files: - if f.endswith(".h") or f.endswith(".cpp"): - print("Formatting: " + f) - subprocess.check_call(["clang-format", "-i", f]) diff --git a/src/haarcascade_frontalface_default.xml b/src/haarcascade_frontalface_default.xml index bc2aa3c..cbd1aa8 100644 --- a/src/haarcascade_frontalface_default.xml +++ b/src/haarcascade_frontalface_default.xml @@ -33311,4 +33311,4 @@ 12 1 3 11 2. <_> 9 12 3 11 2. - \ No newline at end of file + diff --git a/src/model/EdgeTraining.py b/src/model/EdgeTraining.py index 55ff228..31c03b7 100644 --- a/src/model/EdgeTraining.py +++ b/src/model/EdgeTraining.py @@ -11,9 +11,7 @@ data_path = "realtime" -train_path = os.path.join( - data_path, "train.pickle" - ) # A path for the train file +train_path = os.path.join(data_path, "train.pickle") # A path for the train file siamese = SiameseNetwork( seed=seed, @@ -27,21 +25,21 @@ ) loader = DataLoader( - width=WIDTH, - height=HEIGHT, - cells=CEELS, - data_path=data_path, - output_path=train_path, - ) + width=WIDTH, + height=HEIGHT, + cells=CEELS, + data_path=data_path, + output_path=train_path, +) loader.load(set_name="train") siamese.fit( - weights_file="weights/weights.h5", - train_path=train_path, - validation_size=0.2, - batch_size=32, - epochs=2, - early_stopping=True, - patience=5, - min_delta=0.1, - ) \ No newline at end of file + weights_file="weights/weights.h5", + train_path=train_path, + validation_size=0.2, + batch_size=32, + epochs=2, + early_stopping=True, + patience=5, + min_delta=0.1, +) diff --git a/src/model/Siamese_Predictor.py b/src/model/Siamese_Predictor.py index f0d5998..813bb0f 100644 --- a/src/model/Siamese_Predictor.py +++ b/src/model/Siamese_Predictor.py @@ -41,6 +41,7 @@ def preprocess_image(filename): return img + # load the model siamese = SiameseNetwork( seed=seed, diff --git a/src/model/__pycache__/utils.cpython-38.pyc b/src/model/__pycache__/utils.cpython-38.pyc deleted file mode 100644 index 0a34ceb..0000000 Binary files a/src/model/__pycache__/utils.cpython-38.pyc and /dev/null differ diff --git a/src/model/message/__pycache__/__init__.cpython-38.pyc b/src/model/message/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 4f78ac3..0000000 Binary files a/src/model/message/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/src/model/message/__pycache__/sms_message.cpython-38.pyc b/src/model/message/__pycache__/sms_message.cpython-38.pyc deleted file mode 100644 index 5e09d02..0000000 Binary files a/src/model/message/__pycache__/sms_message.cpython-38.pyc and /dev/null differ diff --git a/src/model/message/sms_message.py b/src/model/message/sms_message.py index 5504b71..7074a66 100644 --- a/src/model/message/sms_message.py +++ b/src/model/message/sms_message.py @@ -1,20 +1,17 @@ -import os -from twilio.rest import Client +import os +from twilio.rest import Client from dotenv import load_dotenv load_dotenv() -account_sid = os.getenv('TWILIO_ACCOUNT_SID') -auth_token = os.getenv('TWILIO_AUTH_TOKEN') +account_sid = os.getenv("TWILIO_ACCOUNT_SID") +auth_token = os.getenv("TWILIO_AUTH_TOKEN") + +from_number = "+18886815709" +to_number = "+19788814542" -from_number = '+18886815709' -to_number = '+19788814542' def send_message(intruder_detected): msg = "Intruder Alert!" if intruder_detected else "Welcome!" client = Client(account_sid, auth_token) - message = client.messages.create( - body=msg, - from_=from_number, - to=to_number) - + message = client.messages.create(body=msg, from_=from_number, to=to_number) diff --git a/src/model/realtime/splits/train.txt b/src/model/realtime/splits/train.txt index 75b4312..11c78de 100644 --- a/src/model/realtime/splits/train.txt +++ b/src/model/realtime/splits/train.txt @@ -2,4 +2,4 @@ David_Han 1 5 David_Han 2 6 David_Han 3 7 David_Han 4 8 -David_Han 5 10 \ No newline at end of file +David_Han 5 10 diff --git a/src/model/utils.py b/src/model/utils.py index e9dd156..cfa8524 100644 --- a/src/model/utils.py +++ b/src/model/utils.py @@ -2,6 +2,7 @@ target_shape = (200, 200) + def preprocess_image(filename): """ Load the specified file as a JPEG image, preprocess it and @@ -25,4 +26,4 @@ def preprocess_triplets(anchor, positive, negative): preprocess_image(anchor), preprocess_image(positive), preprocess_image(negative), - ) \ No newline at end of file + ) diff --git a/utils/haarcascade_frontalface_default.xml b/utils/haarcascade_frontalface_default.xml index bc2aa3c..cbd1aa8 100644 --- a/utils/haarcascade_frontalface_default.xml +++ b/utils/haarcascade_frontalface_default.xml @@ -33311,4 +33311,4 @@ 12 1 3 11 2. <_> 9 12 3 11 2. - \ No newline at end of file + diff --git a/utils/motion_detection.cpp b/utils/motion_detection.cpp index 15f2cfa..23de50b 100644 --- a/utils/motion_detection.cpp +++ b/utils/motion_detection.cpp @@ -1,45 +1,42 @@ -#include #include +#include const double MIN_CONTOUR_SIZE = 3000; // Adjust this threshold as needed -bool detect_motion(std::string im_path1, std::string im_path2) -{ - - // load images - cv::Mat image1 = cv::imread(im_path1); - cv::Mat image2 = cv::imread(im_path2); - - // preprocess - cv::Mat gray1, gray2; - - cv::cvtColor(image1, gray1, cv::COLOR_BGR2GRAY); - cv::cvtColor(image2, gray2, cv::COLOR_BGR2GRAY); - cv::GaussianBlur(gray1, gray1, cv::Size(21, 21), 0); - cv::GaussianBlur(gray2, gray2, cv::Size(21, 21), 0); - - cv::Mat diff; - cv::absdiff(gray1, gray2, diff); - - cv::Mat thresh; - cv::threshold(diff, thresh, 25, 255, cv::THRESH_BINARY); - - std::vector> contours; - cv::findContours(thresh, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); - - for (int i = 0; i < contours.size(); i++) - { - cv::drawContours(image2, contours, i, cv::Scalar(0, 255, 0), 2); - } +bool detect_motion(std::string im_path1, std::string im_path2) { + + // load images + cv::Mat image1 = cv::imread(im_path1); + cv::Mat image2 = cv::imread(im_path2); + + // preprocess + cv::Mat gray1, gray2; + + cv::cvtColor(image1, gray1, cv::COLOR_BGR2GRAY); + cv::cvtColor(image2, gray2, cv::COLOR_BGR2GRAY); + cv::GaussianBlur(gray1, gray1, cv::Size(21, 21), 0); + cv::GaussianBlur(gray2, gray2, cv::Size(21, 21), 0); + + cv::Mat diff; + cv::absdiff(gray1, gray2, diff); + + cv::Mat thresh; + cv::threshold(diff, thresh, 25, 255, cv::THRESH_BINARY); + + std::vector> contours; + cv::findContours(thresh, contours, cv::RETR_EXTERNAL, + cv::CHAIN_APPROX_SIMPLE); + + for (int i = 0; i < contours.size(); i++) { + cv::drawContours(image2, contours, i, cv::Scalar(0, 255, 0), 2); + } - bool motionDetected = false; - for (int i = 0; i < contours.size(); i++) - { - if (cv::contourArea(contours[i]) > MIN_CONTOUR_SIZE) - { - motionDetected = true; - break; - } + bool motionDetected = false; + for (int i = 0; i < contours.size(); i++) { + if (cv::contourArea(contours[i]) > MIN_CONTOUR_SIZE) { + motionDetected = true; + break; } - return motionDetected; + } + return motionDetected; }