sqllover999
sqllover999

Reputation: 21

process input image & make duplicate image,& store in another directory

i want it to read input image from a directory & make duplicate image and store in another output directory.Now problem is input image,output image and script is in same path.I want input image directory and output image directory

This is what I have so far

import pandas as pd
import os
import shutil


import re

#reads csv

df = pd.read_csv('rosary.csv')
df['Image'] = df.ImageName + "_" + df.ImageWChain + ".jpg"

#checking if column "ImageWChain" has "jpg" extension,then concat .jpg
if ".jpg" not in df.ImageWChain:
    df['ImageWChain'] = df.ImageWChain + ".jpg"

if ".jpg" not in df.ImageName:
    df['ImageName'] = df.ImageName + ".jpg"


#writes to new csv
df.to_csv('new.csv',index=False)
old_image = df.ImageName
new_image = df.Image



#creates duplicate images with renamed imagename

input_path='D:/New/Input_ImageFolder'
output_path='D:/New/Output_ImageFolder'

input_file=os.path.join(input_path,old_image)
output_file=os.path.join(output_path,new_image)



for old_image, new_image in zip(df.ImageName, df.Image):
    shutil.copy2(input_file, output_file)

Upvotes: 0

Views: 120

Answers (1)

Simon MC. Cheng
Simon MC. Cheng

Reputation: 291

Instead of copying by shutil.copy2, you have to indicate the input and output file path.

For example you have the paths defined as:

input_path='D:\\New\\Input_ImageFolder\\'
output_path='D:\\New\\Output_ImageFolder\\'

Next, you have to issue the following codes BEFORE you run the copy command:

input_file=os.path.join(input_path,old_image)
output_file=os.path.join(output_path,new_image)

Then, you can perform the copy operation as you mentioned:

shutil.copy2(input_file, output_file)

Upvotes: 1

Related Questions