YOLO-series
YOLO-series copied to clipboard
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file
I am struggling with draw_box__py36.py.
I keep getting the following error. Any advice?
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file ~/modules/imgproc/src/color.cpp, line 11079
Traceback (most recent call last):
File "/Users/student/darknet/part6 - draw_box_py36.py", line 52, in
[Finished in 6.736s]
I had this issue but got it solved by fixin the image path . basically my image path was incorrect
I got your problem then I downloaded a picture and reset the path like this
img = cv2.imread('D:\chaos\play\camera1\people.jpg', cv2.IMREAD_COLOR)
I have the same issue and after searching on Google for the problem. I get the problem is the thumbs.db file which is created in your folder. If you go on folder options in controle panel and select show hidden files option you will see the thumbs.db file along with your image file in that same folder imread is trying to read your image. Therefore as a solution you should have to delete the thumbs.db file first. Then no more assertion error for opencv. Cvtcolor.
I have this problem :
None OpenCV(3.4.1) Error: Assertion failed ((scn == 3 || scn == 4) && (depth == 0 || depth == 5)) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 11214 error in image /app/Data/Image/FetchScreenSeed/355837.jpg
I think my code is incapable to read some images. What can I do ?
If it's only a few, I'd recommend writing a quick script to figure out which ones and remove them
this is my script :
-- coding: utf-8 --
Copyright EffiScience 2019
""" DOC-STRING ABOUT THIS FILE PURPOSES """
###############################################################################
Import
###############################################################################
import cv2 import numpy as np import pandas as pd import os
from sklearn.cluster import KMeans from sklearn.metrics import silhouette_score import matplotlib matplotlib.use('Agg') # noqa from matplotlib import pyplot as plt from matplotlib.patches import Circle from scipy import stats import math
import screenseed.computation.image_processing.preprocessing_image as prep_i import screenseed.utility.sql as sql from screenseed.config import (IMAGE_DATA_HOME, OBJECT_STORAGE_URL, SQLALCHEMY_DATABASE_URI)
###############################################################################
Classes and methods definition
###############################################################################
###############################################################################
Classes and methods definition
############################################################################### analysis_id = [221] ana_id_str = str(analysis_id[0]) dir_path = "/app/Data/Image/"+ana_id_str if name == "main": dict_load = {"analysis_id": analysis_id, "container_encoding_id": [1, 12, 85, 96]} # foldering_meth = ["analysis_id", "container_encoding_name"] # meta_data = prep_i.download_image_processed(dict_load, # foldering=foldering_meth, # naming="sensor_data_id", # processing=prep_i.identity, # zip_it=False, # prefix_cycle=True)
# meta_data.to_pickle(dir_path + "/meta.pkl")
meta_data = pd.read_pickle(dir_path + "/meta.pkl")
container_list = np.unique(meta_data["container_encoding_id"].values)
X = []
Y = []
df_res = pd.DataFrame(columns = ["container_encoding_id", "sensor_data_id", "center_x", "center_y","theo_center_x","theo_center_y","d_x","d_y","d"])
for container in container_list:
df_container = meta_data.loc[meta_data["container_encoding_id"] == container]
for img_path in df_container["file_path"].values:
try:
img = cv2.imread(img_path)
#img = cv2.resize(img, (2400,2400,3), fx=2400, fy=2400, fz=3)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# (2) Find the target yellow color region in HSV
hsv_lower = (25, 100, 50)
hsv_upper = (33, 255, 255)
mask = cv2.inRange(hsv, hsv_lower, hsv_upper)
# (3) morph-op to remove horizone lines
kernel = np.ones((15,15), np.uint8)
mask2 = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
moments = cv2.moments(mask2)
a = (int(moments["m10"]/moments["m00"]), int(moments["m01"]/moments["m00"]))
# theoretical center = ....
b = get_size(img_path)
# d_x =
# d_y =
# d
print(a)
# c'est dans row que tu ajoutes les valeurs que tu veux qui iront dans le dataframe
row = {"container_encoding_id": container,
"sensor_data_id": img_path,
"center_x": a[0],
"center_y": a[1],
"d_x": b[0]-a[0],
"theo_center_x":b[0]/2,
"theo_center_y":b[1]/2,
"d_y": b[1]-a[1],
"d": math.sqrt((b[0]-a[0])*(b[0]-a[0])-(b[1]-a[1])*(b[1]-a[1]))}
#X.append(a[0])
#Y.append(a[1])
df_res = df_res.append(row, ignore_index=True)
except:
print("error in image " + str(img_path))
file_path_res_pkl = dir_path + "/res.pkl"
df_res.to_pickle(file_path_res_pkl)
file_path_res_csv = dir_path + "/res.csv"
df_res.to_csv(file_path_res_csv)
#variance_x = variance(X)
#varience_y = variance(Y)
#mean_x = mean(X)
#mean_y = mean(Y)
df_res = pd.read_pickle(file_path_res_pkl)
# print(df_res)
df_res["center_x"] = df_res["center_x"].astype(float)
df_res["center_y"] = df_res["center_y"].astype(float)
# print(df_res["center_x"].mean())
# print(df_res.groupby(["container_encoding_id"])["center_x", "center_y"].mean())
# print(df_res.groupby(["container_encoding_id"])["center_x", "center_y"].var())
mean = df_res.groupby(["container_encoding_id"])["center_x", "center_y", "d_y", "d_x", "d"].mean()
variance = df_res.groupby(["container_encoding_id"])["center_x", "center_y", "d_y", "d_x", "d"].var()
file_path_var_csv = dir_path + "/var.csv"
variance.to_csv(file_path_var_csv)
file_path_mean_csv = dir_path + "/mean.csv"
mean.to_csv(file_path_mean_csv)
# Il ne faut pas que la variable 221 soithardcodé
Did you check your folder for hidden files. I have got in trouble in this error and finally it resolved after i deleted the thumbs.db file.
Fetulhak Abdurahman (MSc) Chair Holder, Computer Engineering TeamSchool of Electrical and Computer Engineering Jimma Institute of Technology Jimma UniversityPhone- 0912690646
On Tuesday, May 14, 2019, 2:37:44 PM GMT+3, Youssef12458 <[email protected]> wrote:
this is my script :
-- coding: utf-8 --
Copyright EffiScience 2019
""" DOC-STRING ABOUT THIS FILE PURPOSES """
###############################################################################
Import
###############################################################################
import cv2 import numpy as np import pandas as pd import os
from sklearn.cluster import KMeans from sklearn.metrics import silhouette_score import matplotlib matplotlib.use('Agg') # noqa from matplotlib import pyplot as plt from matplotlib.patches import Circle from scipy import stats import math
import screenseed.computation.image_processing.preprocessing_image as prep_i import screenseed.utility.sql as sql from screenseed.config import (IMAGE_DATA_HOME, OBJECT_STORAGE_URL, SQLALCHEMY_DATABASE_URI)
###############################################################################
Classes and methods definition
###############################################################################
###############################################################################
Classes and methods definition
############################################################################### analysis_id = [221] ana_id_str = str(analysis_id[0]) dir_path = "/app/Data/Image/"+ana_id_str if name == "main": dict_load = {"analysis_id": analysis_id, "container_encoding_id": [1, 12, 85, 96]}
foldering_meth = ["analysis_id", "container_encoding_name"]
meta_data = prep_i.download_image_processed(dict_load,
foldering=foldering_meth,
naming="sensor_data_id",
processing=prep_i.identity,
zip_it=False,
prefix_cycle=True)
meta_data.to_pickle(dir_path + "/meta.pkl")
meta_data = pd.read_pickle(dir_path + "/meta.pkl") container_list = np.unique(meta_data["container_encoding_id"].values)
X = [] Y = []
df_res = pd.DataFrame(columns = ["container_encoding_id", "sensor_data_id", "center_x", "center_y","theo_center_x","theo_center_y","d_x","d_y","d"]) for container in container_list: df_container = meta_data.loc[meta_data["container_encoding_id"] == container] for img_path in df_container["file_path"].values: try:
img = cv2.imread(img_path)
#img = cv2.resize(img, (2400,2400,3), fx=2400, fy=2400, fz=3)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# (2) Find the target yellow color region in HSV
hsv_lower = (25, 100, 50)
hsv_upper = (33, 255, 255)
mask = cv2.inRange(hsv, hsv_lower, hsv_upper)
# (3) morph-op to remove horizone lines
kernel = np.ones((15,15), np.uint8)
mask2 = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
moments = cv2.moments(mask2)
a = (int(moments["m10"]/moments["m00"]), int(moments["m01"]/moments["m00"]))
# theoretical center = ....
b = get_size(img_path)
# d_x =
# d_y =
# d
print(a)
# c'est dans row que tu ajoutes les valeurs que tu veux qui iront dans le dataframe
row = {"container_encoding_id": container,
"sensor_data_id": img_path,
"center_x": a[0],
"center_y": a[1],
"d_x": b[0]-a[0],
"theo_center_x":b[0]/2,
"theo_center_y":b[1]/2,
"d_y": b[1]-a[1],
"d": math.sqrt((b[0]-a[0])*(b[0]-a[0])-(b[1]-a[1])*(b[1]-a[1]))}
#X.append(a[0])
#Y.append(a[1])
df_res = df_res.append(row, ignore_index=True)
except:
print("error in image " + str(img_path))
file_path_res_pkl = dir_path + "/res.pkl" df_res.to_pickle(file_path_res_pkl) file_path_res_csv = dir_path + "/res.csv" df_res.to_csv(file_path_res_csv) #variance_x = variance(X) #varience_y = variance(Y) #mean_x = mean(X) #mean_y = mean(Y)
df_res = pd.read_pickle(file_path_res_pkl)
print(df_res)
df_res["center_x"] = df_res["center_x"].astype(float) df_res["center_y"] = df_res["center_y"].astype(float)
print(df_res["center_x"].mean())
print(df_res.groupby(["container_encoding_id"])["center_x", "center_y"].mean())
print(df_res.groupby(["container_encoding_id"])["center_x", "center_y"].var())
mean = df_res.groupby(["container_encoding_id"])["center_x", "center_y", "d_y", "d_x", "d"].mean() variance = df_res.groupby(["container_encoding_id"])["center_x", "center_y", "d_y", "d_x", "d"].var() file_path_var_csv = dir_path + "/var.csv" variance.to_csv(file_path_var_csv) file_path_mean_csv = dir_path + "/mean.csv" mean.to_csv(file_path_mean_csv)
Il ne faut pas que la variable 221 soithardcodé
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
Did you check your folder for hidden files. I have got in trouble in this error and finally it resolved after i deleted the thumbs.db file.
Fetulhak Abdurahman (MSc) Chair Holder, Computer Engineering TeamSchool of Electrical and Computer Engineering Jimma Institute of Technology Jimma UniversityPhone- 0912690646
On Tuesday, May 14, 2019, 2:32:32 PM GMT+3, Youssef12458 <[email protected]> wrote:
I have this problem :
None OpenCV(3.4.1) Error: Assertion failed ((scn == 3 || scn == 4) && (depth == 0 || depth == 5)) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 11214 error in image /app/Data/Image/FetchScreenSeed/355837.jpg
I think my code is incapable to read some images. What can I do ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
How can I check that ?
which OS are you using?
Fetulhak Abdurahman (MSc) Chair Holder, Computer Engineering TeamSchool of Electrical and Computer Engineering Jimma Institute of Technology Jimma UniversityPhone- 0912690646
On Tuesday, May 14, 2019, 3:30:52 PM GMT+3, Youssef12458 <[email protected]> wrote:
How can I check that ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
if you are using windows. open the folder which holds your image file go to organize then goto folder and search options then goto view then check on the show hidden files, folders and drives button
cheers!
Fetulhak Abdurahman (MSc) Chair Holder, Computer Engineering TeamSchool of Electrical and Computer Engineering Jimma Institute of Technology Jimma UniversityPhone- 0912690646
On Tuesday, May 14, 2019, 3:30:52 PM GMT+3, Youssef12458 <[email protected]> wrote:
How can I check that ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
which OS are you using? Fetulhak Abdurahman (MSc) Chair Holder, Computer Engineering TeamSchool of Electrical and Computer Engineering Jimma Institute of Technology Jimma UniversityPhone- 0912690646 On Tuesday, May 14, 2019, 3:30:52 PM GMT+3, Youssef12458 [email protected] wrote: How can I check that ? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
Im using Ubuntu 18.04
OpenCV(3.4.1) Error: Assertion failed ((scn == 3 || scn == 4) && (depth == 0 || depth == 5)) in cv::cvtColor, file C:\Miniconda3\conda-bld\opencv-suite_1533128839831\work\modules\imgproc\src\color.cpp, line 11214 Traceback (most recent call last)