Jan-04-2019, 05:12 PM
(Jan-04-2019, 05:00 PM)nilamo Wrote: So the files you're trying to open are inC:\Users\gonca\Anaconda3\lib\site-packages\Desktop\cityscape
andC:\Users\gonca\Anaconda3\lib\site-packages\Desktop\landscape
, correct? If not, then I'd suggest either usingos.chdir()
to change where you think you are to match where your file actually is, or using absolute paths to reference your files/folders. Here's an example of using os.chdir():
1import
os
import
pathlib current_file
=
pathlib.Path(__file__) current_location
=
current_file.parent.absolute() os.chdir(current_location)
# references from here on out to relative paths will be relative to wherever this file exists print(os.getcwd())
the files that i'm tring to read are at
C:\Users\gonca\Desktop\landscape
and
C:\Users\gonca\Desktop\cityscape
I've tried to put that address but i've got another error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
error Traceback (most recent call last) <ipython - input - 18 - 1ea0691ca06e > in <module> 1 dir1 = os.listdir(r 'C:/Users/gonca/Desktop/cityscape' ) 2 dir2 = os.listdir(r 'C:/Users/gonca/Desktop/landscape' ) - - - - > 3 name,img = uploadImg(dir1, dir2) <ipython - input - 17 - 831c56f87f59 > in uploadImg(dir1, dir2) 10 11 orig = cv2.imread(r 'C:/Users/gonca/Desktop/landscape' + file ) - - - > 12 orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB) 13 cityscape = cv2.resize(orig,( 512 , 512 )) 14 #cityscape_original.append(cityscape) error: OpenCV( 3.4 . 2 ) c:\miniconda3\conda - bld\opencv - suite_1534379934306\work\modules\imgproc\src\color.hpp: 253 : error: ( - 215 :Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<3,4,-1>,struct cv::Set<0,2,5>,2>::CvtHelper' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from sklearn.decomposition import NMF from matplotlib import pyplot as plt import cv2 import numpy as np import os import sys import statistics ## upload imgs e returns names e imgs def uploadImg(dir1,dir2): cityscape_original = [] landscape_original = [] nameList = [[] for _ in range ( 512 )] imgList = [[] for _ in range ( 512 )] for file in os.listdir(r 'C:/Users/gonca/Desktop/landscape' ): if file .endswith( ".jpg" ): nameList[ 0 ].append( file ) orig = cv2.imread(r 'C:/Users/gonca/Desktop/landscape' + file ) orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB) cityscape = cv2.resize(orig,( 512 , 512 )) #cityscape_original.append(cityscape) imgList[ 0 ].append(cityscape) for file in os.listdir(r 'C:/Users/gonca/Desktop/cityscape' ): if file .endswith( ".jpg" ): nameList[ 1 ].append( file ) orig = cv2.imread(r 'C:/Users/gonca/Desktop/cityscape' + file ) orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB) landscape = cv2.resize(orig,( 512 , 512 )) #landscape_original.append(landscape) imgList[ 1 ].append(landscape) return nameList,imgList dir1 = os.listdir(r 'C:/Users/gonca/Desktop/cityscape' ) dir2 = os.listdir(r 'C:/Users/gonca/Desktop/landscape' ) name,img = uploadImg(dir1, dir2) |