-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from SoongSilComputingClub/release-0.2.0
Release 0.2.0
- Loading branch information
Showing
69 changed files
with
2,455 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Docker Test | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
env: | ||
DOCKER_IMAGE: ghcr.io/swthewhite/myproject | ||
VERSION: ${{ github.sha }} | ||
NAME: newdevelop | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup docker buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Cache docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ env.VERSION }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Login to ghcr | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GHCR_TOKEN }} | ||
|
||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
push: true | ||
tags: ${{ env.DOCKER_IMAGE }}:latest | ||
|
||
deploy: | ||
needs: build | ||
name: Deploy | ||
runs-on: [ self-hosted ] | ||
steps: | ||
- name: Login to ghcr | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GHCR_TOKEN }} | ||
|
||
- name: Docker run | ||
run: | | ||
docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest | ||
docker run -d -p 3000:3000 --name ${{ env.NAME }} --restart always ${{ env.DOCKER_IMAGE }}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from utils.image_sender import ImageSender | ||
|
||
if __name__ == "__main__": | ||
# 클래스 인스턴스 생성 및 실행 | ||
upload_url = 'http://localhost:3000/uploadfile' | ||
upload_filename = 'photo.jpg' | ||
image_sender = ImageSender(upload_url, upload_filename, "cv") | ||
image_sender.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import cv2 | ||
|
||
|
||
class CvImageCreater: | ||
def __init__(self, ksize=12): | ||
self.ksize = ksize | ||
self.blur_enabled = True | ||
|
||
def blurImage(self, frame, x, y, w, h): | ||
roi = frame[y:y+h, x:x+w] | ||
roi = cv2.blur(roi, (self.ksize, self.ksize)) | ||
frame[y:y+h, x:x+w] = roi | ||
|
||
def toggleBlur(self): | ||
self.blur_enabled = not self.blur_enabled | ||
|
||
def createImage(self): | ||
cam = cv2.VideoCapture(0) | ||
|
||
if not cam.isOpened(): | ||
print('No camera!') | ||
return | ||
|
||
try: | ||
ret, frame = cam.read() | ||
if not ret: | ||
print('No frame') | ||
return | ||
|
||
key = cv2.waitKey(1) | ||
print(key) | ||
print(self.blur_enabled) | ||
|
||
if key == -1 and self.blur_enabled: | ||
x, y, w, h = 450, 400, 80, 10 | ||
for _ in range(8): | ||
self.blurImage(frame, x, y, w, h) | ||
x += 3 | ||
y += h | ||
self.blurImage(frame, 390, 460, 40, 20) | ||
|
||
fliped = cv2.flip(frame, -1) | ||
cv2.imwrite('photo.jpg', fliped) | ||
|
||
except KeyboardInterrupt: | ||
print('Image creation interrupted') | ||
|
||
finally: | ||
cam.release() | ||
|
||
|
||
if __name__ == "__main__": | ||
image_creater = CvImageCreater() | ||
image_creater.createImage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from picamera2 import Picamera2 | ||
import time | ||
|
||
import cv2 | ||
|
||
|
||
class PiImageCreater: | ||
def __init__(self, ksize, cam): | ||
self.ksize = ksize | ||
self.cam = cam | ||
|
||
def blurImage(self, frame, x, y, w, h): | ||
roi = frame[y:y+h, x:x+w] | ||
roi = cv2.blur(roi, (self.ksize, self.ksize)) | ||
frame[y:y+h, x:x+w] = roi | ||
|
||
def toggleBlur(self): | ||
self.blur_enabled = not self.blur_enabled | ||
|
||
def createImage(self): | ||
try: | ||
self.cam.capture_file("photo.jpg") | ||
except KeyboardInterrupt: | ||
print('Image creation interrupted') | ||
|
||
|
||
if __name__ == "__main__": | ||
picam2 = Picamera2() | ||
picam2.start() | ||
image_creater = PiImageCreater(12, picam2) | ||
image_creater.createImage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
import time | ||
from datetime import datetime | ||
|
||
from utils.image_creater.cv2 import CvImageCreater | ||
from utils.image_creater.pi import PiImageCreater | ||
|
||
|
||
class ImageSender: | ||
def __init__(self, upload_url, upload_filename, camera_type): | ||
self.upload_url = upload_url | ||
self.upload_filename = upload_filename | ||
if camera_type == "cv": | ||
self.image_creater = CvImageCreater() | ||
else: | ||
self.image_creater = PiImageCreater() | ||
|
||
def send_img(self): | ||
try: | ||
# 이미지 파일을 열고 서버에 업로드 | ||
with open(self.upload_filename, 'rb') as f: | ||
r = requests.post(self.upload_url, files={'file': f}) | ||
return r | ||
except Exception as e: | ||
print(f"Error sending image: {e}") | ||
return None | ||
|
||
def toggle_blur(self): | ||
self.image_creater.toggleBlur() # ImageCreater의 블러 토글 호출 | ||
|
||
def run(self): | ||
print("ImageSender.py Activate") | ||
while True: | ||
try: | ||
# 이미지 생성 | ||
self.image_creater.createImage() | ||
|
||
# 이미지 업로드 시도 | ||
r = self.send_img() | ||
if r is not None: | ||
print(datetime.now(), r.text) | ||
|
||
# 2초 대기 | ||
time.sleep(2) | ||
except KeyboardInterrupt: | ||
print("ImageSender.py 종료") | ||
break |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM python:3.11.1 | ||
|
||
WORKDIR /code | ||
|
||
COPY ./requirements.txt /code/requirements.txt | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
RUN apt-get install -y tzdata | ||
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime | ||
|
||
RUN apt-get update | ||
RUN apt-get -y install libgl1-mesa-glx wget | ||
RUN pip install --no-cache-dir -r /code/requirements.txt | ||
|
||
COPY . /code | ||
|
||
WORKDIR /code/WebServer/yolo_data | ||
|
||
RUN wget https://pjreddie.com/media/files/yolov3.weights | ||
|
||
WORKDIR /code/WebServer | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.