0

I am reading one image using cv2.imread() function. I want to store image title that is 10_left.jpeg in one variable and that name write in one CSV file. code is as below:

import cv2

img = cv2.imread('home/pycharmprojects/diabetic/testing/10_left.jpeg')
print("shape of original image ",img.shape)
cv2.imshow('Orgninal Image',img)
2
  • Are you asking about reading/writing the EXIF data or something else? Commented Feb 15, 2019 at 20:49
  • How is your csv file formatted? Also you need a cv2.waitKey after imshow. Commented Feb 15, 2019 at 20:49

2 Answers 2

1

To clarify, you want to read the image name from a CSV file and use that to open the image with open-cv? In that case, you'll just need to parse your csv file with csv module. If your CSV is just rows of image names, this is fairly easy.

import cv2
import csv

ifile = open(‘test.csv’, “rb”)
reader = csv.reader(ifile)

imageNames = []
for row in reader
    imageNames.append(row)

img = cv2.imread(imageNames[0])
print("shape of original image ",img.shape)
cv2.imshow('Original Image',img)
cv2.waitkey(0)

If your csv is more involved, the link above should help get you on your way.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your solution but you get it wrong. I am reading image by its path by using imread function and that time I want to store its name in CSV file. it's not like I am reading image name from CSV file.
0

You can create a custom class for image object and store actual image and file name in separate variables.

class MyImage:
    img = None
    name = ''

    def __init__(self,name):
        self.name = name
        self.img = cv2.imread(name)

myImage = MyImage('10_left.jpeg')

To write the name in CSV file, simple get the value of myImage.name attribute

2 Comments

if this solution is the one you wanted, please up-vote and verify as the correct answer thank you
I am a beginner with python really don't know about python object-oriented concept. please help me to understand that code and tell me how to write each name in CSV file cause i have 200 images

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.