Skip to content

Commit

Permalink
Merge pull request #7 from SoongSilComputingClub/release-0.2.0
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
swthewhite authored Apr 18, 2024
2 parents 071e91f + 23cd15f commit c3f24d7
Show file tree
Hide file tree
Showing 69 changed files with 2,455 additions and 614 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
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
8 changes: 8 additions & 0 deletions CamDevice/main.py
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()
54 changes: 54 additions & 0 deletions CamDevice/utils/image_creater/cv2.py
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()
31 changes: 31 additions & 0 deletions CamDevice/utils/image_creater/pi.py
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()
47 changes: 47 additions & 0 deletions CamDevice/utils/image_sender.py
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 removed Daily_Accessor.txt
Empty file.
Empty file removed Data_Folder/Daily_Accessor.txt
Empty file.
Empty file removed Data_Folder/Today_Accessor.txt
Empty file.
Empty file removed Data_Folder/nCnt.txt
Empty file.
23 changes: 23 additions & 0 deletions Dockerfile
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"]
74 changes: 0 additions & 74 deletions Makerspace.py

This file was deleted.

Loading

0 comments on commit c3f24d7

Please sign in to comment.