Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions 03117_bae/main.py

This file was deleted.

Binary file removed 03122_Ji/스터디 1주차_지예은.docx
Binary file not shown.
Binary file added 03151_minsuje/hw/week1(git)/git command.xlsx
Binary file not shown.
Empty file.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import cv2 #opencv
import threading #thread 분할 (webcam streamming 중에 반복문으로 프레임을 읽어와서 보여줘야하는데 다른작업도 해야해서 들고옴)


class VideoPlayer:
def __init__(self):
self.file_address = 'C:/ROKEY/ROMiserables/ROMiserables/03151_minsuje/hw/week2(py)/CCTV_project/CCTV_minsuje/src/recorder/cctv_recorded/'
self.capture = None
self.video_play_thread = None
self.is_playing = False
self.allowed_formats = ['mp4', 'mkv', 'mov','avi']

def open_video_file(self, file_name):
"""비디오 파일을 열어 재생하는 함수."""
# 파일 형식 확인
if not any(file_name.endswith(fmt) for fmt in self.allowed_formats):
print(f"지원되지 않는 파일 형식입니다: {file_name}")
return

# 비디오 파일 읽기 없으면 return
self.capture = cv2.VideoCapture(self.file_address+file_name)
if not self.capture.isOpened():
print("비디오 파일을 열 수 없습니다.")
return

# 재생중 플래그 및 쓰래드 시작
self.is_playing = True
self.video_play_thread = threading.Thread(target=self._play_video)
self.video_play_thread.start()

def _play_video(self):
while self.is_playing:
ret, frame = self.capture.read()
if not ret:
print("비디오 끝.")
break

# 비디오 피드를 화면에 표시
cv2.imshow('Video Playback', frame)

# 'ESC'를 눌러 종료
if cv2.waitKey(1) & 0xFF == 27: # ESC 키 코드
self.is_playing = False
break
self.release_resources()

def release_resources(self):
"""비디오 자원 해제."""
self.is_playing = False
if self.capture:
self.capture.release()
cv2.destroyAllWindows()

def stop_video(self):
"""비디오 재생 중지."""
self.is_playing = False
if self.video_play_thread and self.video_play_thread.is_alive():
self.video_play_thread.join()

# play_cam = VideoPlayer()
# play_cam.open_video_file("")
# play_cam._play_video()
# play_cam.release_resources()
# play_cam.stop_video()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import cv2
import datetime

class VideoRecorder():
def __init__(self):
self.path_record_adress = "C:/ROKEY/ROMiserables/ROMiserables/03151_minsuje/hw/week2(py)/CCTV_project/CCTV_minsuje/src/recorder/cctv_recorded/"
self.recording = None

def open_video_record(self, frame_size):
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
file_name = f"{self.path_record_adress}CCTV_{timestamp}.avi"
fourcc = cv2.VideoWriter_fourcc(*'XVID')
self.out = cv2.VideoWriter(str(file_name), fourcc, 20.0, frame_size)
print(f"녹화 시작: {file_name}")

def on_air_recording(self,frame):
if self.recording:
self.recording.write(frame)

def stop_recording(self):
if self.out:
self.out.release()
self.out = None
print("녹화 중지 및 저장.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import cv2
class WebCamSelecter():
def __init__(self):
self.cam = None
self.selected_cam = None
self.cam_list = []
self.cam_name = {}
self.find_cam_list()

# 카메라를 찾을때 window 11에서만 그럴진 모르겠지만 장치가 한번 이상 인식되면 계속 남아서 연결할수 있게 뜨는데 실제로 연결 안되있으면 error를 반환하긴함
# 지금 이컴퓨터에 전에 다른 웹캠을 연결 한적있는데 그게 1,2번으로 잡혀 있고, 연결되어있지 않아서 error가 뜸 동작은 함함
def find_cam_list(self):
index = 0 # 웹카메라는 노트북의 경우 0번이 노트북 카메라고 나머지가 1~n의 번호로 불러올수있음
f_cam_list = []
while(True):
self.cam = cv2.VideoCapture(index)
ret, frame = self.cam.read() # ret은 카메라 상태가 동작가능하면true, 불가능하면 false 프래임은 현재 프레임을 받아옴
if(not ret):
break # 더 이상 읽어올 카메라 없음.
self.cam_list.append(index) # 캠의 번호만 저장하는게 프로그램에 덜무리감감
self.cam.release() # 카메라 메모리 해제 cam에는 더이상 카메라 정보를 받지 않음
self.cam_name[index] = ' '
index +=1

def select_cam(self,cam_num=0):
self.selected_cam = self.cam_list[cam_num]

def name_set(self,cam_num:int, name:str):
if len(name) <2:
raise Exception("카메라 이름의 문자는 길이가 1보다 커야합니다.")
if name in self.cam_name.values():
raise Exception(f"이미 '{name}'라는 카메라 이름이 존재합니다.")
self.cam_name[cam_num] = name

def rename(self,last_name,new_name):
if len(new_name) <2:
raise Exception("카메라 이름의 문자는 길이가 1보다 커야합니다.")
if new_name in self.cam_name.values():
raise Exception(f"이미 '{new_name}'라는 이름이 존재합니다.")
for index, name in self.cam_name.items():
if(last_name==name):
self.cam_name[index] = new_name

def name2index(self,name:str):
for index, cam_name in self.cam_name.items():
if cam_name==name:
return int(index)


# webcam = WebCamSelecter()
# webcam.find_cam_list()
# print(webcam.cam_name)
# webcam.name_set(0,"노트북카메라")
# webcam.name_set(1,"엘가토 웹캠")
# webcam.name_set(2,"모르겠음 웹캠")
# print(webcam.cam_name)
# print(webcam.name2index("엘가토 웹캠"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import cv2 #opencv
import threading #thread 분할 (webcam streamming 중에 반복문으로 프레임을 읽어와서 보여줘야하는데 다른작업도 해야해서 들고옴)
os sys

from recorder.video_player import VideoRecorder

class WebCamStreamer():
def __init__(self,cam_num=0): # 노트북은 캠이 기본 탑재 되어있어서 그냥 아무것도 선택안하면 노트북 웹캠 자체그대로로
self.selected_cam_number = cam_num
self.capture = None
self.stream_thread = None
self.is_streamming = False
#self.recorder = VideoRecorder()

def open_cam(self):
self.capture = cv2.VideoCapture(self.selected_cam_number,cv2.CAP_DSHOW)
if not self.capture.isOpened(): # 열려있는지 확인
raise Exception("카메라가 연결되지 않아 스트리밍을 할 수 없습니다.")
self.is_streamming = True #스트리밍 상태가 True가 되야 스트리밍 함수 내부에 while로 돌릴수 있음.
self.stream_thread = threading.Thread(target=self.cam_streamming) #쓰레드 분할 타겟 스트림 함수
self.stream_thread.start() #스트림 스래드 활성화

def cam_streamming(self):
while self.is_streamming:
ret, frame = self.capture.read() #정보를 읽어와서
if not ret: #상태가 False이면 읽어올수 없는 상태임
print("프레임을 읽을 수 없습니다. 다시 시도합니다....")
continue
# frame은 하나의 이미지임 그래서 cv2의 이미지를 읽어오는 imshow함수 사용
cv2.imshow("streamming_On_Air...",frame)
# cv.waitkey는 입력 키의 값을 나타내는 정수를 반환하는데
# 비트 마스크 0xFF로 받은 키 값의 하위 8비트만 확인한다
# 27번은 esc키의 입력값이고 해당 값이 들어오면 스트리밍을 종료한다.
key = cv2.waitKey(1)&0xFF
if key==27:
break
# if key== ord('r'):
# if self.recorder.recording==False:
# video_frame_size = (int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
# int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
# self.recorder.open_video_record(video_frame_size)
# self.is_streamming = True
# else:
# self.recorder.stop_recording()
# self.is_recording = False
# print("녹화 중지!")
self.close_stream_resources()
# if self.recorder.recording:
# self.recorder.stop_recording()
# self.is_recording = False
# print("녹화 중지!")

def close_ALL_resources(self):
self.close_stream_resources()
self.close_thread_resources()

def close_thread_resources(self):
if self.stream_thread and self.stream_thread.is_alive():
self.stream_thread.join() # 스레드가 종료될 때까지 기다림

def close_stream_resources(self):
if self.capture:
self.capture.release() # 연결 해제
cv2.destroyAllWindows() # opencv로 연 모든 윈도우창 닫기
self.is_streamming = False

play_cam = WebCamStreamer()
play_cam.open_cam()
play_cam.cam_streamming()
play_cam.close_ALL_resources()
46 changes: 46 additions & 0 deletions 03151_minsuje/hw/week2(p)/CCTV_project/README_project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CCTV 개발 프로젝트
## 목적
- 본 Rokey 커리큘럼내에 있는 딥러닝 맛보기

- 본 Rokey 커리큘럼내에 있는 OpenCV 맛보기
- 딥러닝보다는 OpenCV사용에 조금 더 초점이 맞춰져 있음

## 절차(목차)
1. 가상환경 생성

2. opencv 라이브러리 설치
3. webcam 열기
- 강의를 위해 사용중인 webcam을 기준으로 제작
- 만일 webcam 없다면, 사용할만한 영상 제공
4. webcam 영상 저장
5. 영상 내 도형 그리기 및 글자 입력(OpenCV 심화)
6. 딥러닝 알고리즘 사용을 위한 환경 설정(cuda 또는 필수 라이브러리 설치) (**중요**)
- 본 프로젝트 담당자의 노트북을 성능을 기준으로 설치할 예정
- 개인 노트북의 성능을 기준으로 설치할 것
7. webcam 영상에 딥러닝 알고리즘 적용
- 본 프로젝트에서는 학습 및 알고리즘 설명을 제외
- 간단한 설명만 추가 예정
8. tracking 알고리즘 적용
- 딥러닝 알고리즘과 동일하게 간단한 정의만 설명 예정
9. people counting 알고리즘 적용



## 내용
### 1. 가상환경 생성

### 2. OpenCV 라이브러리 설치

### 3. Webcam 열기
### 4. Webcam 영상 저장
### 5. 이미지내 선 및 도형 그리기 및 글자 입력(OpenCV 심화)

### 6. 딥러닝 알고리즘 사용을 위한 cuda 설치 및 환경 셋팅

### 7. webcam 영상에 딥러닝 알고리즘 적용

### 8. tracking 알고리즘 적용

### 9. people counting 알고리즘 적용


81 changes: 81 additions & 0 deletions 03151_minsuje/hw/week2(p)/CCTV_project/minsuje_cctv_project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 배재성님의 CCTV 프로젝트

- 작성자 : 제민수(ROKEY 3기생 DR-05131)
- 작성 기간 : 2025-01-22~(진행중)
- 버전 관리 : 1.2.1 ver
- 0.1.x 1주차 웹캠 열기까지 할 예정


-
## 📜목차

- [개요](#개요)
[작성의 목적](#작성의-목적)
[CCTV 목적](CCTV-목적)

- [프로그램](#프로그램)

- [기타](#기타)
__________________________
________________________

## 개요
### 작성의 목적
- ROKEY 3기 프로그램 진행에서 스터디 그룹에서 코딩 리뷰 및 학습 내용 공유를 위함.
- 스터디 피드백 내용 정리
- 추가예정
- 해당 문서는 ROKEY 3기생 DR-03151제민수가 작성 하였으며, 문서 및 파일은 직접 수정하지 않는다.

### CCTV 목적
- 본 Rokey 커리큘럼내에 있는 딥러닝 맛보기

- 본 Rokey 커리큘럼내에 있는 OpenCV 맛보기
- 딥러닝보다는 OpenCV사용에 조금 더 초점이 맞춰져 있음

___이라고 함_________________________________________________________________________
- 영상 읽고 저장 및 영상 내에 도형 및 글자 입력.(????)
- 영상 내에 사람 트레킹 딥러닝 알고리즘 작성 및 사람 카운팅
_______________________
_____________
## 프로그램

### 프로젝트 진행 순서
1. 가상환경 생성

2. opencv 라이브러리 설치
3. webcam 열기
- 강의를 위해 사용중인 webcam을 기준으로 제작
- 만일 webcam 없다면, 사용할만한 영상 제공
4. webcam 영상 저장
5. 영상 내 도형 그리기 및 글자 입력(OpenCV 심화)
6. 딥러닝 알고리즘 사용을 위한 환경 설정(cuda 또는 필수 라이브러리 설치) (**중요**)
- 본 프로젝트 담당자의 노트북을 성능을 기준으로 설치할 예정
- 개인 노트북의 성능을 기준으로 설치할 것
7. webcam 영상에 딥러닝 알고리즘 적용
- 본 프로젝트에서는 학습 및 알고리즘 설명을 제외
- 간단한 설명만 추가 예정
8. tracking 알고리즘 적용
- 딥러닝 알고리즘과 동일하게 간단한 정의만 설명 예정
9. people counting 알고리즘 적용

### 입출력 정리
#### 입력
- webcam data
#### 출력
- people counting num

### 필수 사용 라이브러리 및 프로그램램
- opencv
- cuda (????????????????????????)

## 기타

### 문제 풀이 진행 순서 및 주의 사항(막쓰고 수정예졍)
#### 진행 순서

#### 주의 사항
1. 제한사항을 꼭 코드작성시 적용 할것.
2. 함수 작성시''''''' 을 이용하여 설명을 꼭 작성 할것


### 체크리스트
13 changes: 13 additions & 0 deletions 03151_minsuje/hw/week2(p)/important road/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 프로그래머스 테스트코드 : 중요한 로드 문제 풀기
> 저는 프로그래머스에 있는 문제를 선택하여 진행하였습니다.
해당 문제풀이 및 작성 도중 필요한 문서까지 작성하였는데
참고하셔도 좋고 참고 하지 않으셔도 좋습니다.
그럼 토요일 스터디에서 뵙겠습니다.
해당 문제에 대한 자세한 사항을 알고 싶으시다면 아래 링크를 참조해 주세요.


https://school.programmers.co.kr/learn/courses/30/lessons/214293

예제 코드는 성공 했는데 아무래도 제출에는 입력되는 량이 커서 그런지.. 시간 초과가 뜨네요...
토요일까지 수정 해보고자는 하는데.... 될진 모르겠습니다. 최대한 수정해서 올려보겠습니다 우선 초안부터 올리겠습니다 다른분들도 문제 풀어는 봐야 되니까요.
우선 어려운문제로 해봤는데 다음에는 스택과 큐 같은 기초 알고리즘 문제를 선택해봐야 겠어요.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading