ROI for image dataset

315 Views Asked by At

I'm trying to find out ROI for an image dataset. I'm able to find ROI for a single image, but when it comes to the whole dataset or multiple images I can't do it.

I tried to use different code from the internet, but nothing worked. `

import cv2
import numpy as np
import os
import random
from matplotlib import pyplot as plt
import matplotlib.image as mpimg

img_folder=r'Shrimp/train/Resized_Dataset'
img_dir = r'Cropped_shrimp'
for i in range(30):
    file = random.choice(os.listdir(img_folder))
    image_path= os.path.join(img_folder, file)
    img=mpimg.imread(image_path)
    ax=plt.subplot(1,30,i+1)
    ax.title.set_text(file)
    plt.imshow(img)
    
roi = cv2.selectROI(img_folder)

ROI_image = img_folder[int(r[1]):int(r[1]+r[3]),
                      int(r[0]):int(r[0]+r[2])]

cv2.imshow("ROI_image", ROI_image)
cv2.waitKey(0)

os.chdir(img_dir)

cv2.imwrite("ROI_image", JPG)

` This is my last approach. I think there're lots of mistake because I'm trying this for the first time.

0

There are 0 best solutions below