<jupyter_start><jupyter_text>These scripts run perfectly on windows, on linux platform there will be issue due to path handling in linux<jupyter_code>import cv2
if __name__ == '__main__' :

    video = cv2.VideoCapture("C:/Users/umar.amanat/Desktop/Mot16-Venice-2.mp4");
    
    # Find OpenCV version
    (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
    
    if int(major_ver)  < 3 :
        fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
        print("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps))
    else :
        fps = video.get(cv2.CAP_PROP_FPS)
        print("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))
    
    video.release();<jupyter_output><empty_output><jupyter_text>Calculating WIdth and Height of frame<jupyter_code>import cv2

vcap = cv2.VideoCapture("C:/Users/umar.amanat/Desktop/Mot16-Venice-2.mp4");

if vcap.isOpened(): 
    height = vcap.get(cv2.CAP_PROP_FRAME_HEIGHT)   # float
    width = vcap.get(cv2.CAP_PROP_FRAME_WIDTH)
    print("video height {} and width {}".format(height, width))<jupyter_output><empty_output><jupyter_text>Saving video frame after skipping particular number of frames<jupyter_code>import os 
import cv2

vid_fold_path = "C:/Users/umar.amanat/Desktop" #Video folder path
video_path = "MOT16-11.mp4"

vidcap = cv2.VideoCapture(os.path.join(vid_fold_path, video_path))
total_frames = vidcap.get(7)
fps = vidcap.get(cv2.cv2.CAP_PROP_FPS)   #fps of video
success,image = vidcap.read() #read video
skip_frame = 5  # number of frame to skip
orig_height = vidcap.get(cv2.CAP_PROP_FRAME_HEIGHT)   # original height of video
orig_width = vidcap.get(cv2.CAP_PROP_FRAME_WIDTH)     #original width of videos
print("frame per second: ", fps)
print("video height {} and width {}".format(orig_height, orig_width))
success = True    #flag for iterating through video's frame
frame_count = 0         #count for storing video file
scaled_height = int(orig_height/32) * 32  #scaled height for yolov2 algo
scaled_width = int(orig_width/32) * 32    #scaled width for yolov2 algo
print("scaled video height {} and scaled width {}".format(scaled_height, scaled_width))

image_count = 0 #counter for counting number of images per folder
folder_count = 0 #counter for counting number of folder
saving_path = "C:/Users/umar.amanat/Desktop/DataSet"


saving_path = os.path.join(saving_path, "folder_")
os.makedirs(saving_path+str(folder_count))

diff_height = 0
diff_widht = 0
#Iterate till last frame of video
while success:
    if (frame_count%skip_frame == 0):
        if(image_count<10):
            diff_height = int(orig_height/2)-int(scaled_height/2)
            diff_width = int(orig_width/2)-int(scaled_width/2)
            image = image[diff_height : int(orig_height-diff_height), diff_width : int(orig_width-diff_width)]
            cv2.imwrite(os.path.join(saving_path+str(folder_count), video_path+"_"+str(image_count))+".png" , image) 
            image_count += 1
        else:
            folder_count += 1;
            saving_path = saving_path #os.path.join(saving_path, "folder_"+str(folder_count))
            os.makedirs(saving_path+str(folder_count))
            image_count = 0
            
    success,image = vidcap.read()    
    frame_count += 1<jupyter_output><empty_output><jupyter_text>Color tuning script<jupyter_code>def rotate_image(image, angle):
    image_center = tuple(np.array(image.shape[1::-1]) / 2)
    rot_mat = cv2.getRotationMatrix2D(image_center, angle, 1.0)
    r_img = cv2.warpAffine(image, rot_mat, image.shape[1::-1], flags=cv2.INTER_LINEAR)  
    return r_img
    #rotate func end here

def brightened_image(image, intensity):
    """
    Argument info
    image: input image
    intesnity: Intensity for brightness
    """
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) #convert it to hsv
    for x in range(0, len(hsv)):
        for y in range(0, len(hsv[0])):
            if(hsv[x, y][2] < 255 - intensity):
                hsv[x, y][2] += intensity
    
    b_img = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) 
    return b_img
    #brightened image end here
def increase_blue(image, intensity):
    """
    Argument info
    image: input image
    intesnity: Intensity for blue color
    """
    for x in range(0, len(image)):
        for y in range(0, len(image[0])):
            if(image[x, y][0] < 255 - intensity):
                image[x, y][0] += intensity
    return image
    #increase blue image end here
def increase_green(image, intensity):
    """
    Argument info
    image: input image
    intesnity: Intensity for green color
    """
    for x in range(0, len(image)):
        for y in range(0, len(image[0])):
            if(image[x, y][1] < 255 - intensity):
                image[x, y][1] += intensity
    return image
    #increase green image end here
def increase_red(image, intensity):
    """
    Argument info
    image: input image
    intesnity: Intensity for green color
    """
    for x in range(0, len(image)):
        for y in range(0, len(image[0])):
            if(image[x, y][2] < 255 - intensity):
                image[x, y][2] += intensity
    return image
    #increase red image end here
def apply_kernel(image, kernel):
    """
    Image: input image
    Kernel : Specify 2D kernel to apply on image 
    """
    image = cv2.filter2D(image, -1, kernel)
    return image

def increase_contrast(image):
    clahe = cv2.createCLAHE(clipLimit=3., tileGridSize=(8,8))
    lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)  # convert from BGR to LAB color space
    l, a, b = cv2.split(lab)  # split on 3 different channels
    l2 = clahe.apply(l)  # apply CLAHE to the L-channel
    lab = cv2.merge((l2,a,b))  # merge channels
    img2 = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)  # convert from LAB to BGR
    return img2

def adding_noise(image):
    row,col,ch = image.shape
    s_vs_p = 0.5
    amount = 0.004
    out = np.copy(image)
    # Salt mode
    num_salt = np.ceil(amount * image.size * s_vs_p)
    coords = [np.random.randint(0, i - 1, int(num_salt))
          for i in image.shape]
    out[coords] = 1

    # Pepper mode
    num_pepper = np.ceil(amount* image.size * (1. - s_vs_p))
    coords = [np.random.randint(0, i - 1, int(num_pepper))
          for i in image.shape]
    out[coords] = 0
    return out
import os 
import cv2
import numpy as np
import glob
import pandas as pd
import json<jupyter_output><empty_output><jupyter_text>Make Image bright<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/BrightImages"
img_cnt = 0 #image_count
br_int = 35     #brightness intensity

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_brght"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        
        ######################## make image bright start ######################################
        br_img = brightened_image(image.copy(), br_int)
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_brght")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_bright"+".png", br_img)     
        ######################## end######################################

        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_brght")+"/"+sub_fold.split('/')[-1]+"_brght"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Make rotation<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/RotateImages"
img_cnt = 0 #image_count
angle = -0.5    #angle for rotation

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_rot"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        rot_img = rotate_image(image.copy(), angle)    #rotated image
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(rot_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
        ######################## Rotate image start ######################################
        
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_rot")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_rot"+".png", rot_img)       
        ######################## end ######################################

        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_rot")+"/"+sub_fold.split('/')[-1]+"_rot"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Increasae Blue Color<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/BlueImages"
img_cnt = 0 #image_count
b_int = 35      #blue color intensity

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_blue"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        blue_img = increase_blue(image.copy(), b_int)    
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(blue_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
       
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_blue")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_blue"+".png", blue_img)       
        ######################## end ######################################


        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_blue")+"/"+sub_fold.split('/')[-1]+"_blue"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Make color green<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/GreenImages"
img_cnt = 0 #image_count
g_int = 35      #green color intensity

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_green"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        green_img = increase_green(image.copy(), g_int)     
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(green_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
       
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_green")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_green"+".png", green_img)       
        ######################## end ######################################


        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_green")+"/"+sub_fold.split('/')[-1]+"_green"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Increase red color intensity<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/RedImages"
img_cnt = 0 #image_count
r_int = 35      #red color intensity

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_red"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        red_img = increase_red(image.copy(), r_int)  
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(red_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
       
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_red")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_red"+".png", red_img)       
        ######################## end ######################################


        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_red")+"/"+sub_fold.split('/')[-1]+"_red"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>increase contrast<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/ContrastImages"
img_cnt = 0 #image_count

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_cont"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        inc_cont = increase_contrast(image.copy())  
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(inc_cont, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
       
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_cont")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_cont"+".png", inc_cont)       
        ######################## end ######################################


        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_cont")+"/"+sub_fold.split('/')[-1]+"_cont"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Sharpen Images<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/SharpImages"
img_cnt = 0 #image_count

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_sharp"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        sharp_kernel = np.array([[0,-1,0], [-1,5,-1], [0,-1,0]])
        sh_img = apply_kernel(image.copy(), sharp_kernel)    #sharp image
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(sh_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
       
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_sharp")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_sharp"+".png", sh_img)       
        ######################## end ######################################


        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_sharp")+"/"+sub_fold.split('/')[-1]+"_sharp"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Adding salt and pepper noise<jupyter_code>img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/NoiseImages"
img_cnt = 0 #image_count

for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_noise"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
        noise_img = adding_noise(image.copy())
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(noise_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
       
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_noise")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_noise"+".png", noise_img)       
        ######################## end ######################################


        img_cnt+=1

    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_noise")+"/"+sub_fold.split('/')[-1]+"_noise"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Following script are only for flipped of annotated images  Mirror script according to folder structure<jupyter_code>import cv2
import os
import random 
import pandas as pd
import glob
import json
import numpy as np


img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/MirrorImages"
img_cnt = 0 #image_count

#this for loop will iterate over base folder
for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_mirror"))
    img_cnt = 0
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image

         ####################### Flipping image ######################################
        hor_flip = cv2.flip( image.copy(), 1 )
         
        
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            json_string['x'] = image.shape[1] - json_string['x'] - json_string['width']
            ann_csv.replace(to_replace=dim, value=str(json_string), inplace=True)
            ann_csv.loc[image_name].loc[box]["region_shape_attributes"] = str(json_string)
        
            """
            following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
            un comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(hor_flip, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        cv2.imwrite(os.path.join(saving_path,  sub_fold.split('/')[-1]+"_mirror")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_mirror"+".png", hor_flip)
        #######################end #####################
        img_cnt+=1
    
    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_mirror")+"/"+sub_fold.split('/')[-1]+"_mirror"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Shifting code according to folder structure<jupyter_code>import cv2
import os
import random 
import pandas as pd
import glob
import json
import numpy as np


img_fold_path = "/home/umcr7/Desktop/Images/" #Video folder path
saving_path = "/home/umcr7/Desktop/ShiftImages"

x_shift = 10    #shifting along x-axis
y_shift = 10    #shifting along y-axis

#this for loop will iterate over base folder
for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    #=================================================================================================
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_shift"))
    img_cnt = 0
    #===================================================================================================
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        image = cv2.imread(image_path) #reading image
         ####################### Flipping image ######################################
        num_rows, num_cols = image.copy().shape[:2]
        translation_matrix = np.float32([ [1,0,x_shift], [0,1,y_shift] ])
        shf_img = cv2.warpAffine(image.copy(), translation_matrix, (num_cols, num_rows))
       
        
        for box in ann_csv.loc[image_name].index:
            dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
            json_string = json.loads(dim)
            json_string['x'] = json_string['x'] + x_shift 
            json_string['y'] = json_string['y'] + y_shift
            ann_csv.replace(to_replace=dim, value=str(json_string), inplace=True)
            ann_csv.loc[image_name].loc[box]["region_shape_attributes"] = str(json_string)
#         #######################end #####################
            """
                following line is for varifying bounding boxes, this will draw bounding boxes after flipping images
                un-comment immediate subsequent line to draw bounding box
            """
#             cv2.rectangle(shf_img, (json_string['x'], json_string['y']), 
#                           (json_string['x'] + json_string['width'], json_string['y']+json_string['height']), (0, 0, 255), 2)
        
        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_shift")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+"_shift"+".png", shf_img)
        
        
        #inner for end here
        img_cnt+=1
    
    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
    ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_shift")+"/"+sub_fold.split('/')[-1]+"_shift"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))<jupyter_output><empty_output><jupyter_text>Scripts for overlay transparent image on other background image<jupyter_code>import random
def transparentOverlay(src , overlay , pos=(0,0),scale = 1):
    """
    :param src: Input Color Background Image
    :param overlay: transparent Image (BGRA)
    :param pos:  position where the image to be blit.
    :param scale : scale factor of transparent image.
    :return: Resultant Image
    """
    overlay = cv2.resize(overlay,(0,0),fx=scale,fy=scale)
    h,w,_ = overlay.shape  # Size of foreground
    rows,cols,_ = src.shape  # Size of background Image
    y,x = pos[0],pos[1]    # Position of foreground/overlay image
    #for randomizing placement of ocerlay image
    y = random.randint(y, y+20)
    x = random.randint(x-5, x+20)
    #loop over all pixels and apply the blending equation
    for i in range(h):
        for j in range(w):
            if x+i >= rows or y+j >= cols:
                continue
            alpha = float(overlay[i][j][3]/255.0) # read the alpha channel 
            src[x+i][y+j] = alpha*overlay[i][j][:3]+(1-alpha)*src[x+i][y+j]
    return src

import cv2
import os
import random 
import pandas as pd
import glob
import json



img_fold_path = "/home/umcr7/Desktop/Images" #images folder path
saving_path = "/home/umcr7/Desktop/OverlayImages"  #saving path for images
bag_image_path = "/home/umcr7/Desktop/Bag-samples/" #specify folder containing bag images to overlay
bag_images = list(glob.iglob(os.path.join(bag_image_path, "*.png"))) #make list of all bag images in specified folder


#this for loop will iterate over base folder
for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["#filename"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    ann_csv.drop(columns=["#filename","file_size", "region_count", "region_id", "file_attributes"], inplace=True)
    img_cnt=0
    os.makedirs(os.path.join(saving_path, sub_fold.split('/')[-1]+"_overlay"))
    for image_path, image_name in zip(sorted(glob.iglob(os.path.join(sub_fold, "*.png"))), ann_csv.index.levels[0]):
        per_img = cv2.imread(image_path)
        for box in ann_csv.loc[image_name].index:
            if(ann_csv.loc[image_name].loc[box]["region_attributes"] == '{"Class":"P"}'):
                if(random.getrandbits(1) == 1):
                    #select random bag, cv2.IMR... for reading image as transparent
                    bag_img = cv2.imread(bag_images[random.randint(1, len(bag_images)-1)], cv2.IMREAD_UNCHANGED)
                    dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
                    json_string = json.loads(dim)
                    #generate random size of bag 
                    bag_img = cv2.resize(bag_img, (int(json_string['width']*random.randint(55, 60)/100), 
                                                   int(json_string['height']*random.randint(40, 45)/100))
                                        , cv2.INTER_CUBIC)
                    bag_y = json_string['y'] + json_string['height'] - int(bag_img.shape[0]*1.5)
                    per_img = transparentOverlay(per_img, bag_img, pos=(json_string['x'], bag_y))
                    cl = ann_csv.loc[image_name].loc[box]["region_attributes"]
                    ann_csv.loc[(image_name, box), "region_attributes"] = '{"Class":"PW"}'
            
            ann_csv.loc[(image_name, box), "im_name"] = sub_fold.split('/')[-1]+"_"+str(img_cnt+1)+".png"            

        cv2.imwrite(os.path.join(saving_path, sub_fold.split('/')[-1]+"_overlay")+"/"+sub_fold.split('/')[-1]+
                    "_"+str(img_cnt)+".png", per_img)
        img_cnt+=1
        
    ann_csv.reset_index(inplace=True)
    ann_csv.drop(columns='level_1', inplace=True)
#     ann_csv.rename({'level_0':'image_name'}, axis=1, inplace=True)
    ann_csv.reset_index(inplace=True)
    ann_csv.drop(ann_csv.columns[0], axis=1, inplace=True)
    ann_csv.drop(ann_csv.columns[0], axis=1, inplace=True)
    ann_csv.rename({'im_name':'image_name'}, axis=1, inplace=True)
    ann_csv.to_csv(os.path.join(saving_path, sub_fold.split('/')[-1]+"_overlay")+"/"+sub_fold.split('/')[-1]+"_overlay"+".csv",
                  index=False)
    print("Processed Folder: {}".format(sub_fold.split('/')[-1]))
   
for sub_fold in sorted(glob.iglob(img_fold_path+"/*")):
    for pic in sorted(glob.iglob(sub_fold+"/*.png")):
        print(pic.spl)<jupyter_output>/home/umcr7/Desktop/to_convert/A10_mirror/A10_0_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_1_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_2_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_3_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_4_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_5_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_6_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_7_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_8_mirror.png
/home/umcr7/Desktop/to_convert/A10_mirror/A10_9_mirror.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_0_shift.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_1_shift.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_2_shift.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_3_shift.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_4_shift.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_5_shift.png
/home/umcr7/Desktop/to_convert/A10_shift/A10_6_shift.png
/home/umcr7[...]<jupyter_text>Convert to voc dataset for darkflow<jupyter_code>import cv2
import os
import random 
import pandas as pd
import glob
import json
import numpy as np
from shutil import copyfile

img_fold_path = "/home/umcr7/Desktop/to_convert" #Video folder path
saving_path = "/home/umcr7/Desktop/DataSet"
# os.makedirs(os.path.join(saving_path, "Images"))
# os.makedirs(os.path.join(saving_path, "Annotation"))

#this for loop will iterate over base folder
for sub_fold in glob.iglob(img_fold_path+"/*"):
    img_ann_path = glob.iglob(sub_fold+"/*.csv")  #path for annotated csv file
    ann_csv = pd.read_csv(list(img_ann_path)[-1])
    labels = ann_csv["image_name"] 
    tuples = list(zip(labels, ann_csv.index.values))
    hier_index = pd.MultiIndex.from_tuples(tuples)
    ann_csv.set_index(hier_index, inplace=True)
    for image_path, image_name in zip(glob.iglob(os.path.join(sub_fold, "*.png")), 
                                      ann_csv.index.levels[0]):
        print(image_path)
        for box in ann_csv.loc[image_name].index:
                #select random bag, cv2.IMR... for reading image as transparent
                dim = ann_csv.loc[image_name].loc[box]["region_shape_attributes"]
                print(ann_csv.loc[image_name].loc[box]["image_name"])
        print('inner loop end')      
#         copyfile(pic, os.path.join(saving_path, "Images/"+pic.split('/')[-1]))<jupyter_output>/home/umcr7/Desktop/to_convert/A5_mirror/A5_3_mirror.png
1.png
1.png
1.png
inner loop end
/home/umcr7/Desktop/to_convert/A5_mirror/A5_4_mirror.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
10.png
inner loop end
/home/umcr7/Desktop/to_convert/A5_mirror/A5_9_mirror.png
2.png
2.png
2.png
2.png
2.png
2.png
2.png
2.png
inner loop end
/home/umcr7/Desktop/to_convert/A5_mirror/A5_6_mirror.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
3.png
inner loop end
/home/umcr7/Desktop/to_convert/A5_mirror/A5_1_mirror.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
4.png
inner loop end
/home/umcr7/Desktop/to_convert/A5_mirror/A5_2_mirror.png
5.png
5.png
5.png
5.png
5.png
5.png
5.png
5.png
5.png
inner loop end
/home/umcr7/Desktop/to_convert/A5_mirror/A5_8_mirror.png
6.png
6.png
6.png
6.png
6.png
6.png
6.png
6.p[...]
{'fraction_non_alphanumeric': 0.17329757883608798, 'fraction_numerical': 0.01915787845189903, 'mean_word_length': 3.5034835113794704, 'pattern_counts': {'":': 2, '<': 69, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '244349', 'license': 'MIT', 'n_tokens_mistral': 14103, 'n_tokens_neox': 13412, 'n_words': 2339, 'path': 'OpenCvEx1-Linux.ipynb', 'repo_name': 'MUmarAmanat/OpenCvPython', 'size': '38783'}