简体   繁体   English

如何解决 AxisError:轴 1 超出维度 0 数组的范围

[英]How to solve AxisError: axis 1 is out of bounds for array of dimension 0

I'm trying out Harry's invisibility cloak but getting Axis error and the display it shows while I run the code wouldn't just go away.我正在试用 Harry 的隐形斗篷,但在运行代码时出现 Axis 错误和它显示的显示不会只是 go 消失。 I mean it's already showing error and I can't close that display tab either unless I close the IDE totally.我的意思是它已经显示错误,除非我完全关闭 IDE,否则我也无法关闭该显示选项卡。 Putting down the code here?把代码放在这里? Can somebody help me figure this out?有人可以帮我解决这个问题吗? How do I solve this axis issue.我该如何解决这个轴问题。 I guess the tab's also got frozen for this reason.我猜这个标签也因为这个原因被冻结了。

import cv2
import numpy as np
import time

cap = cv2.VideoCapture(0)
time.sleep(3)
background=0

for i in range(30):
    ret,background = cap.read()

background = np.flip(background,axis=1)

while(cap.isOpened()):
    ret, img = cap.read()
    img = np.flip(img, axis = 1)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    blurred = cv2.GaussianBlur(hsv, (35, 35), 0)
    lower = np.array([0,120,70])
    upper = np.array([10,255,255])
    mask1 = cv2.inRange(hsv, lower, upper)
    lower_red = np.array([170,120,70])
    upper_red = np.array([180,255,255])
    mask2 = cv2.inRange(hsv, lower_red, upper_red)

    mask = mask1 + mask2
    mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, 
                            np.ones((5,5),np.uint8))
    img[np.where(mask == 255)] = background[np.where(mask == 255)]
    cv2.imshow('Display',img)
    k = cv2.waitKey(10)
    if k == 27:
        break

I'm getting error inside the for loop of the code, let me note the error notification:我在代码的 for 循环中遇到错误,请注意错误通知:

     8 for i in range(60):
     9     ret,background = cap.read()
---> 10 background = np.flip(background,axis=1)

AxisError: axis 1 is out of bounds for array of dimension 0 AxisError:轴 1 超出维度 0 数组的范围

The code works without modification on my laptop.该代码无需修改即可在我的笔记本电脑上运行。 Probably cap.read() returns no images on your system.可能cap.read()在您的系统上不返回任何图像。 You should always check the ret value to check if the cap.read() succeeds.您应该始终检查ret值以检查cap.read()是否成功。

It seems you are using odd colour ranges.看来您使用的是奇怪的颜色范围。 Shadows in my face are vanishing under the cloak.我脸上的阴影在斗篷下消失了。 I tried with green colour only (hue 40-80) which works very nice.我只尝试了绿色(色调 40-80),效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 遇到 AxisError:轴 1 超出维度 0 数组的范围 - Encountering AxisError: axis 1 is out of bounds for array of dimension 0 AxisError:轴 1 超出维度 1 数组的范围 - AxisError: axis 1 is out of bounds for array of dimension 1 numpy.AxisError:轴 1 超出维度 1 数组的范围 - numpy 数组 - numpy.AxisError: axis 1 is out of bounds for array of dimension 1 - numpy array numpy.AxisError:来源:轴 2 超出了维度 2 数组的范围 - numpy.AxisError: source: axis 2 is out of bounds for array of dimension 2 np.linalg.norm AxisError:轴 1 超出维度 1 数组的范围 - np.linalg.norm AxisError: axis 1 is out of bounds for array of dimension 1 AxisError:计算类的准确性时,轴 1 超出维度 1 数组的范围 - AxisError: axis 1 is out of bounds for array of dimension 1 when calculating accuracy of classes 2D 数组的 median_absolute_deviation 抛出 AxisError: axis 1 is out of bounds for array of dimension 1 - median_absolute_deviation of 2D array throws AxisError: axis 1 is out of bounds for array of dimension 1 AxisError:计算 roc_auc_score 时,轴 1 超出维度 1 数组的范围 - AxisError: axis 1 is out of bounds for array of dimension 1 when calculating roc_auc_score 我无法解决“轴-1超出维度0数组的范围”的问题 - I can't solve issue “axis -1 is out of bounds for array of dimension 0” 分类器:轴 1 超出维度 1 数组的范围 - classifier : axis 1 is out of bounds for array of dimension 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM