python-opencv-ValueError: setting an array element with a sequence

el/2023/9/24 21:56:23

Error描述

C:\WORK\Python\python.exe C:/Users/雪山飞狐/Desktop/研究生资料/数字图像处理/shiyan1.py
Traceback (most recent call last):File "C:/Users/雪山飞狐/Desktop/研究生资料/数字图像处理/shiyan1.py", line 23, in <module>img_4 = downsampling(img, 4)File "C:/Users/雪山飞狐/Desktop/研究生资料/数字图像处理/shiyan1.py", line 19, in downsamplingnew_img[a][b] = img[i][j]
ValueError: setting an array element with a sequence.

解决方案

翻译:ValueError:使用序列设置数组元素。
这里我遇到该情况的原因是

new_img = np.zeros((x, y), dtype=img.dtype)

初始化的时候没有给深度初始化,却在后面尝试插入一个RGB数组
改为

 new_img = np.zeros((x, y,3), dtype=img.dtype)

就好了


http://www.ngui.cc/el/3419047.html

相关文章

python-opencv-matplotlib灰度图可视化处理

参考文章1、golgotha的ttps://www.jianshu.com/p/de9013f181d7 一、Demo 一、1.热度图 利用matplotlib可视化一张图片的灰度图。 纵横坐标为图片的像素点位置(x, y),此像素点的灰度值z(x, y)当作z轴上的取值。 首先利用plot_surface分析某张图片的灰度图 import matplotli…

python-AttributeError: module 'matplotlib' has no attribute 'contourf'

错误内容 Traceback (most recent call last):File "C:/Users/雪山飞狐/Desktop/学习总结/ML100天/Code/Day_4.py", line 30, in <module>plt.contourf(X1, X2, classifer.predict(np.array([X1

(LaTex)CTex使用详细教程与资料

一份其实很短的LaTex入门文档 &#xff08;LaTex)CTex的初次使用心得及入门教程 一、 为啥子要用LaTex &#xff08;1&#xff09;待编辑文档规模尺度相关&#xff1a; 学位论文&#xff0c;书籍的编辑用LaTex就比较方便 &#xff08;2&#xff09;编号的方便&#xff1a; …

Pytorch Error:RuntimeError: Assertion cur_target 0 cur_target n_classes failed

ERROR 使用pytorch的函数 torch.nn.CrossEntropyLoss()计算Loss时报错 或者 loss criterion(output, target) 报错&#xff1a; RuntimeError: Assertion cur_target > 0 && cur_target < n_classes failed解决方法&#xff1a; 原因一&#xff1a;模型输出与…

Pytorch Error: ValueError: Expected input batch_size (324) to match target batch_size (4) Log In

ERROR 运行到loss = criterion(output, target)时 报错: ValueError: Expected input batch_size (324) to match target batch_size (4) Log In解决方法 打印 class Net(nn.Module):def __init__(se

Pytorch Erroe:invalid argument 0: Sizes of tensors must match except in dimension 0. Got 62 and 56 i

Error invalid argument 0: Sizes of tensors must match except in dimension 0. Got 62 and 56 in dimension 2 at C:\Users\builder\AppData\Local\Temp\pip-req-build-9msmi1s9\aten\src\TH/generic/THTensor.cpp:689

Pytorch Error:RuntimeError:CUDA error: out of memory [in torch.load]

Error: 当加载模型时&#xff1a; model.load_state_dict(torch.load(xxx.pth))Error:RuntimeError:CUDA error: out of memory解决方法 原因1-CUDA显存不足 解决办法&#xff1a;换成显存更大的显卡 原因2-显卡被占用 当存在多个显卡时&#xff0c;pytorch默认使用0号显…

cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\segmentation.cpp:161:

问题描述 在运用分水岭分割的时候&#xff0c;发现该常见错误 kernel np.ones((3, 3), np.uint8) sure_bg cv.dilate(waterimg, kernel, iterations3)# 确定背景 dist cv.distanceTransform(waterimg, cv.DIST_L2, 3)# 距离变换 ret, sure_fg cv.threshold(dist, dist.ma…

Pytorch Error 常见总结

Pytorch Error 1-输入数据维度不同 Pytorch Error:invalid argument 0: Sizes of tensors must match except in dimension 0. Got 62 and 56 i 2-模型中shape不一致 Pytorch Error: ValueError: Expected input batch_size (324) to match target batch_size (4) Log In …

记一次院赛CTF的WEB题(入门级别)

目录签到一签到二口算小天才easy php录取查询我爱pythonSpring这次院赛的题目比较基础&#xff0c;适合给刚入门CTF的小白提供一个大致CTF解题思路。&#xff08;主要因为本人小白&#xff0c;表示能学到不少东西。&#xff09;签到一 题目中直接给了flag&#xff0c;提交就可…