Python Forum

Full Version: error: (-215:Assertion failed)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone

I'm getting this 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'
Can you guys helping me?

This is the code i have:
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)
Thanks for the support

Gonçalo Matos
The GitHub for OpenCV has a closed ticket on this. The response was that the base image is likely not a three-channel image and has likely been saved as a single-channel. Other resolutions I've seen recommend a try...except block for it. Perhaps use a try...except with a grayscale to RGB constant instead.