【问题标题】:Python OpenCV libpng warning: iCCP: known incorrect sRGB profilePython OpenCV libpng 警告:iCCP:已知不正确的 sRGB 配置文件
【发布时间】:2018-11-28 00:54:00
【问题描述】:

拥有 face_recognition 代码并尝试更改某些图像的 BGR。使用这一行运行代码:python3 encode_faces.py --dataset dataset --encodings encodings.pickle。有一种方法可以从下面绕过错误:

OpenCV(3.4.1) Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/opencv-20180529-55469-97fkx6/opencv-3.4.1/modules/imgproc/src/color.cpp, line 11115
Traceback (most recent call last):
  File "encode_faces.py", line 38, in <module>
    rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(3.4.1) /tmp/opencv-20180529-55469-97fkx6/opencv-3.4.1/modules/imgproc/src/color.cpp:11115: error: (-215) scn == 3 || scn == 4 in function cvtColor

这是我的源代码:

# import the necessary packages 
#asa s ruleaza 
# python3 encode_faces.py --dataset dataset --encodings encodings.pickle
from imutils import paths
import face_recognition
import argparse
import pickle
import cv2
import os

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--dataset", required=True,
    help="path to input directory of faces + images")
ap.add_argument("-e", "--encodings", required=True,
    help="path to serialized db of facial encodings")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
    help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())
# grab the paths to the input images in our dataset
print("[INFO] quantifying faces...")
imagePaths = list(paths.list_images(args["dataset"]))

# initialize the list of known encodings and known names
knownEncodings = []
knownNames = []

# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
    # extract the person name from the image path
    print("[INFO] processing image {}/{}".format(i + 1,
        len(imagePaths)))
    name = imagePath.split(os.path.sep)[-2]

    # load the input image and convert it from RGB (OpenCV ordering)
    # to dlib ordering (RGB)
    image = cv2.imread(imagePath)
    rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # detect the (x, y)-coordinates of the bounding boxes
    # corresponding to each face in the input image
    boxes = face_recognition.face_locations(rgb,
        model=args["detection_method"])

    # compute the facial embedding for the face
    encodings = face_recognition.face_encodings(rgb, boxes)

    # loop over the encodings
    for encoding in encodings:
        # add each encoding + name to our set of known names and
        # encodings
        knownEncodings.append(encoding)
        knownNames.append(name)

# dump the facial encodings + names to disk
print("[INFO] serializing encodings...")
data = {"encodings": knownEncodings, "names": knownNames}
f = open(args["encodings"], "wb")
f.write(pickle.dumps(data))
f.close()

打印(image.shape) 错误=

[INFO] quantifying faces...
[INFO] processing image 1/1401
libpng warning: iCCP: known incorrect sRGB profile
(1080, 1920, 3)
[INFO] processing image 2/1401
Traceback (most recent call last):
  File "encode_faces.py", line 38, in <module>
    print(image.shape)
AttributeError: 'NoneType' object has no attribute 'shape'

【问题讨论】:

  • image.shape看完后能不能打印出来
  • 更新了问题流程。没有属性“形状”
  • 第二张图片好像有问题?

标签: python opencv libpng


【解决方案1】:

照片似乎有误。他们必须重新校准。我运行另一个脚本来保存照片以创建新数据集。第二次成功了。

【讨论】:

    猜你喜欢
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多