Skip to content

Commit

Permalink
Merge pull request #12 from CornellDataScience/pre-commit
Browse files Browse the repository at this point in the history
Replace clang-format scripts with pre-commit hooks
  • Loading branch information
bryantpark04 authored Mar 3, 2024
2 parents d9b7148 + d368843 commit 95e4dfe
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 141 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/clang-format.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..`

Expand All @@ -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`

Expand Down
18 changes: 0 additions & 18 deletions ci/clang-format-checker.sh

This file was deleted.

23 changes: 0 additions & 23 deletions ci/clang-format.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/haarcascade_frontalface_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33311,4 +33311,4 @@
12 1 3 11 2.</_>
<_>
9 12 3 11 2.</_></rects></_></features></cascade>
</opencv_storage>
</opencv_storage>
34 changes: 16 additions & 18 deletions src/model/EdgeTraining.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
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,
)
1 change: 1 addition & 0 deletions src/model/Siamese_Predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def preprocess_image(filename):

return img


# load the model
siamese = SiameseNetwork(
seed=seed,
Expand Down
Binary file removed src/model/__pycache__/utils.cpython-38.pyc
Binary file not shown.
Binary file removed src/model/message/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
19 changes: 8 additions & 11 deletions src/model/message/sms_message.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/model/realtime/splits/train.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ David_Han 1 5
David_Han 2 6
David_Han 3 7
David_Han 4 8
David_Han 5 10
David_Han 5 10
3 changes: 2 additions & 1 deletion src/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

target_shape = (200, 200)


def preprocess_image(filename):
"""
Load the specified file as a JPEG image, preprocess it and
Expand All @@ -25,4 +26,4 @@ def preprocess_triplets(anchor, positive, negative):
preprocess_image(anchor),
preprocess_image(positive),
preprocess_image(negative),
)
)
2 changes: 1 addition & 1 deletion utils/haarcascade_frontalface_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33311,4 +33311,4 @@
12 1 3 11 2.</_>
<_>
9 12 3 11 2.</_></rects></_></features></cascade>
</opencv_storage>
</opencv_storage>
73 changes: 35 additions & 38 deletions utils/motion_detection.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv2/opencv.hpp>

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<std::vector<cv::Point>> 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<std::vector<cv::Point>> 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;
}

0 comments on commit 95e4dfe

Please sign in to comment.