gpt4 book ai didi

python - dct 中的断言失败(类型 == CV_32FC1 || 类型 == CV_64FC1)

转载 作者:太空宇宙 更新时间:2023-11-03 21:11:44 28 4
gpt4 key购买 nike

我正在尝试获取图像的 dct。一开始我遇到了错误

The function/feature is not implemented (Odd-size DCT's are not implemented) in dct

所以我用零填充图像以使其大小均匀

但现在我得到错误:

Assertion failed (type == CV_32FC1 || type == CV_64FC1) in dct

我该如何解决这个问题?下面是我在 python 中所做的

    img = cv2.imread(filepath)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresholded = cv2.threshold(gray,200,255,cv2.THRESH_BINARY)

img = cv2.cvtColor(thresholded, cv2.COLOR_GRAY2BGR)
gray = thresholded
gray = gray.astype('float32')

#padding
BLUE = [255,0,0]
rows,cols = gray.shape
nrows = cv2.getOptimalDFTSize(rows)
ncols = cv2.getOptimalDFTSize(cols)
right = ncols - cols
bottom = nrows - rows
bordertype = cv2.BORDER_CONSTANT
gray = cv2.copyMakeBorder(img,0,bottom,0,right,bordertype, value = 0)
gray = gray.astype('float32')
dct=cv2.dct(gray)

最佳答案

import cv2
import numpy as np
img = cv2.imread('imgColor.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret,thresholded = cv2.threshold(gray,200,255,cv2.THRESH_BINARY)

img = cv2.cvtColor(thresholded, cv2.COLOR_GRAY2BGR)
gray = thresholded
gray = np.float32(gray)/255.0
dct=cv2.dct(gray)

#padding
# BLUE = [255,0,0]
# rows,cols = gray.shape
# nrows = cv2.getOptimalDFTSize(rows)
# ncols = cv2.getOptimalDFTSize(cols)
# right = ncols - cols
# bottom = nrows - rows
# bordertype = cv2.BORDER_CONSTANT
# gray = cv2.copyMakeBorder(img,0,bottom,0,right,bordertype, value = 0)
# gray = np.float32(gray)/255.0
# dct=cv2.dct(gray)

这对我有用!找到这个here

关于python - dct 中的断言失败(类型 == CV_32FC1 || 类型 == CV_64FC1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31949210/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com