Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # [Staging Ground: Opening an Image using Python in VS - Stack Overflow](https://stackoverflow.com/staging-ground/79988044#comment141126638_79988044)
- # date: 2026.07.30
- import cv2 as cv
- import os
- import matplotlib.pyplot as plt
- # --- functions ---
- def readAndWriteImage():
- imPath = ('C:\\Body Type Examination App\\Images\\IMG_9991.jpeg')
- img = cv.imread(imPath)
- imgRGB = cv.cvtColor(img.cv.COLOR_BGR2RGB)
- plt.figure()
- plt.imshow(imgRGB)
- plt.show()
- # --- main ---
- #if __name__ == '__main__': # WRONG: with indentation - so it is inside function `readAndWriteImage()`
- # readAndWriteImage()
- if __name__ == '__main__': # CORRECT: without indentation - so it is outside function `readAndWriteImage()`
- readAndWriteImage()
Advertisement
Add Comment
Please, Sign In to add comment