파이썬 numpy.array사용방법

조회수 282회

numpy.array([,,,]), numpy.min(), numpy.max()를 이용해서 최소 사람수, 최대 사람수를 표현하고 싶습니다. 배열을 제가 직접선언하는게 아니라 동영상에서 받아와야 되는거같아서 접근법을 모르겟습니다.

결과 화면에 텍스트를 t= 354, min_persons = 3, max_persons = 5와 같이 4개 동영상의 최대 사람수, 최소 사람수를 표시하는게 제가 원하는 결과입니다. numpy선언을 어떻게 해야하는건가요?

from itertools import count 
import cv2 
import numpy as np 
cap = cv2.VideoCapture('./data/vtest.avi') 
if (not cap.isOpened()):   
 print('Error opening video') 

height, width = (int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)), 
             int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))) 
#1 
bgMog1 = cv2.createBackgroundSubtractorMOG2() 
bgMog2 = cv2.createBackgroundSubtractorMOG2(varThreshold=25, 
                                        detectShadows=False) 
bgKnn1 = cv2.createBackgroundSubtractorKNN() 
bgKnn2 = cv2.createBackgroundSubtractorKNN(dist2Threshold=1000, 
                                       detectShadows=False) 
#2 
AREA_TH = 80 # area   threshold 
def findObjectAndDraw(bImage, src): 
res = src.copy() 
bImage = cv2.erode(bImage,None, 5) 
bImage = cv2.dilate(bImage,None,5)     
bImage = cv2.erode(bImage,None, 7)     
contours, _ = cv2.findContours(bImage, 
                  cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 
cv2.drawContours(src, contours, -1, (255,0,0), 1) 
count = 0 
for i, cnt in enumerate(contours): 
    area = cv2.contourArea(cnt) 
    if area > AREA_TH: 
        x, y, width, height = cv2.boundingRect(cnt) 
        cv2.rectangle(res, (x, y), (x+width, y+height), (0,0,255), 2) 
        count += 1 
return (res, count) 
#3 
t = 0 
while True: 
ret, frame = cap.read() 
if not ret: 
    break 
t+=1 
print('t =', t) 
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
blur = cv2.GaussianBlur(frame,(5,5),0.0) 

key = cv2.waitKey(25) #0 
if key == 27: 
    break 
if cap.isOpened(): 
cap.release() 
cv2.destroyAllWindows()
  • 들여쓰기 좀 잘 수정해 줄래요? nowp 2022.6.3 23:08
  • 음.. 제가 이사이트를 처음이용해봐서 들여쓰기를 수정해달라는게 어떤건가요? 조성민 2022.6.4 00:22

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)