Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to Save Each ROI Seperately

Hello,

I have below code:

Blockquote

import cv2 cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

n_rows = 3 n_images_per_row = 3 while(True):

Capture frame-by-frame

ret, frame = cap.read() height, width, ch = frame.shape roi_height = int(height / n_rows) roi_width = int(width / n_images_per_row) images = [] for x in range(0, n_rows): for y in range(0,n_images_per_row): tmp_image=frame[xroi_height:(x+1)roi_height, yroi_width:(y+1)roi_width] images.append(tmp_image)

Display the resulting sub-frame

for x in range(0, n_rows): for y in range(0, n_images_per_row): cv2.imshow(str(1+y+xn_images_per_row), images[xn_images_per_row+y]) cv2.moveWindow(str(x * n_images_per_row + y + 1), 100 + (y * roi_width), 50 + (x * roi_height))

if cv2.waitKey(1) & 0xFF == ord('q'): break

cv2.imshow(cap.release()) cv2.destroyAllWindows()

I would like to save each frame seperately.

click to hide/show revision 2
None

updated 2019-10-11 04:48:12 -0600

berak gravatar image

How to Save Each ROI Seperately

Hello,

I have below code:

Blockquote

import cv2
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

1080)

n_rows = 3 n_images_per_row = 3 while(True):

while(True): # Capture frame-by-frame

frame-by-frame ret, frame = cap.read() height, width, ch = frame.shape roi_height = int(height / n_rows) roi_width = int(width / n_images_per_row) images = [] for x in range(0, n_rows): for y in range(0,n_images_per_row): tmp_image=frame[xroi_height:(x+1)roi_height, yroi_width:(y+1)roi_width] images.append(tmp_image)

tmp_image=frame[x*roi_height:(x+1)*roi_height, y*roi_width:(y+1)*roi_width] images.append(tmp_image) # Display the resulting sub-frame

sub-frame for x in range(0, n_rows): for y in range(0, n_images_per_row): cv2.imshow(str(1+y+xn_images_per_row), images[xn_images_per_row+y]) cv2.imshow(str(1+y+x*n_images_per_row), images[x*n_images_per_row+y]) cv2.moveWindow(str(x * n_images_per_row + y + 1), 100 + (y * roi_width), 50 + (x * roi_height))

roi_height))

if cv2.waitKey(1) & 0xFF == ord('q'): break

break

cv2.imshow(cap.release()) cv2.destroyAllWindows()

cv2.destroyAllWindows()

I would like to save each frame seperately. seperately.

click to hide/show revision 3
None

updated 2019-10-11 04:50:28 -0600

berak gravatar image

How to Save Each ROI Seperately

Hello,

I have below code:

import cv2
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

n_rows = 3
n_images_per_row = 3
while(True):
 # Capture frame-by-frame
 ret, frame = cap.read()
 height, width, ch = frame.shape
 roi_height = int(height / n_rows)
 roi_width = int(width / n_images_per_row)
 images = []
 for x in range(0, n_rows):
 for y in range(0,n_images_per_row):
 tmp_image=frame[x*roi_height:(x+1)*roi_height, y*roi_width:(y+1)*roi_width]
 images.append(tmp_image)
 # Display the resulting sub-frame
 for x in range(0, n_rows):
 for y in range(0, n_images_per_row):
 cv2.imshow(str(1+y+x*n_images_per_row), images[x*n_images_per_row+y])
 cv2.moveWindow(str(x * n_images_per_row + y + 1), 100 + (y * roi_width), 50 + (x * roi_height))

 if cv2.waitKey(1) & 0xFF == ord('q'):
 break

 cv2.imshow(cap.release())
 cv2.destroyAllWindows()

I would like to save each frame seperately.

How to Save Each ROI Seperately

Hello,

I have below code:

import cv2
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

n_rows = 3
n_images_per_row = 3
while(True):

    # Capture frame-by-frame
    ret, frame = cap.read()
    height, width, ch = frame.shape
    roi_height = int(height / n_rows)
    roi_width = int(width / n_images_per_row)
    images = []
    for x in range(0, n_rows):
    for y in range(0,n_images_per_row):
    tmp_image=frame[x*roi_height:(x+1)*roi_height, y*roi_width:(y+1)*roi_width]
    images.append(tmp_image)
    # Display the resulting sub-frame
    for x in range(0, n_rows):
    for y in range(0, n_images_per_row):
    cv2.imshow(str(1+y+x*n_images_per_row), images[x*n_images_per_row+y])
    cv2.moveWindow(str(x * n_images_per_row + y + 1), 100 + (y * roi_width), 50 + (x * roi_height))

    if cv2.waitKey(1) & 0xFF == ord('q'):
    break

    cv2.imshow(cap.release())

cv2.destroyAllWindows()

I would like to save each frame seperately.