Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with reading a path
#11
(Jan-04-2019, 05:00 PM)nilamo Wrote: So the files you're trying to open are in C:\Users\gonca\Anaconda3\lib\site-packages\Desktop\cityscape and C:\Users\gonca\Anaconda3\lib\site-packages\Desktop\landscape, correct? If not, then I'd suggest either using os.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():
import 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:

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'
i've put the address like this:



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)
Reply


Messages In This Thread
Problem with reading a path - by gkiller007 - Jan-04-2019, 03:34 PM
RE: Problem with reading a path - by ichabod801 - Jan-04-2019, 03:36 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 03:42 PM
RE: Problem with reading a path - by nilamo - Jan-04-2019, 03:59 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 04:08 PM
RE: Problem with reading a path - by Axel_Erfurt - Jan-04-2019, 04:28 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 04:34 PM
RE: Problem with reading a path - by Axel_Erfurt - Jan-04-2019, 04:41 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 04:49 PM
RE: Problem with reading a path - by nilamo - Jan-04-2019, 05:00 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 05:12 PM
RE: Problem with reading a path - by Axel_Erfurt - Jan-04-2019, 06:21 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 06:32 PM
RE: Problem with reading a path - by Axel_Erfurt - Jan-04-2019, 06:39 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 06:43 PM
RE: Problem with reading a path - by nilamo - Jan-04-2019, 06:52 PM
RE: Problem with reading a path - by gkiller007 - Jan-04-2019, 11:59 PM
RE: Problem with reading a path - by ichabod801 - Jan-05-2019, 01:49 AM
RE: Problem with reading a path - by gkiller007 - Jan-05-2019, 02:27 AM
RE: Problem with reading a path - by snippsat - Jan-05-2019, 03:47 AM
RE: Problem with reading a path - by ichabod801 - Jan-05-2019, 04:18 AM
RE: Problem with reading a path - by gkiller007 - Jan-05-2019, 02:16 PM
RE: Problem with reading a path - by snippsat - Jan-05-2019, 02:40 PM
RE: Problem with reading a path - by gkiller007 - Jan-05-2019, 02:42 PM
RE: Problem with reading a path - by snippsat - Jan-05-2019, 03:26 PM
RE: Problem with reading a path - by gkiller007 - Jan-05-2019, 04:31 PM
RE: Problem with reading a path - by snippsat - Jan-05-2019, 06:34 PM
RE: Problem with reading a path - by gkiller007 - Jan-05-2019, 08:24 PM
RE: Problem with reading a path - by snippsat - Jan-05-2019, 09:11 PM
RE: Problem with reading a path - by gkiller007 - Jan-05-2019, 09:19 PM
RE: Problem with reading a path - by snippsat - Jan-05-2019, 10:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel file reading problem max70990 1 951 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Loop reading csv file problem faustineaiden 1 1,629 Dec-11-2021, 08:40 AM
Last Post: ibreeden
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,278 Sep-09-2021, 01:25 PM
Last Post: Yoriz
Exclamation Path sacn problem lucky511 10 4,054 Jun-24-2021, 12:09 PM
Last Post: Axel_Erfurt
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,615 May-07-2021, 03:26 PM
Last Post: herwin
  Strange Problem when reading from excel faryad13 3 2,478 Nov-04-2020, 03:48 PM
Last Post: DeaD_EyE
  problem about maze path finder Simurg 2 2,017 Aug-16-2020, 01:10 PM
Last Post: Simurg
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 2,073 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  Problem reading data from file player1681 2 3,843 May-22-2020, 08:57 AM
Last Post: player1681
  Problem with reading and writing to file. darktitan 2 2,358 Jul-20-2019, 06:06 PM
Last Post: darktitan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020