Python Forum
error: (-215:Assertion failed)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error: (-215:Assertion failed)
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 10,647 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  SQLite Unique constraint failed error djwilson0495 3 13,279 Aug-14-2020, 05:23 PM
Last Post: ndc85430
  pip install -e ., ERROR: Failed building wheel for pyfarmhash mostafaPython 1 6,232 Jun-09-2020, 08:24 PM
Last Post: mcmxl22
  opencv on mac: Assertion Failed RandomCoder 0 1,637 Feb-16-2020, 06:17 PM
Last Post: RandomCoder
  Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesyste jiapei100 0 10,065 Feb-11-2020, 01:27 PM
Last Post: jiapei100
  Test Case Assertion Error moga2003 10 5,376 Mar-18-2019, 01:06 AM
Last Post: moga2003
  Assertion Error Mateoo 2 2,141 Jan-20-2019, 03:59 PM
Last Post: stullis
  python import sybpydb error: DLL load failed: The specified module could not be found andieDu 3 7,598 Apr-04-2018, 06:58 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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