Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python img不是numpy数组,也不是标量数组。。。但是';img&x27;isn';t在我的代码中用作变量名_Python_Opencv_Houghlinesp - Fatal编程技术网

Python img不是numpy数组,也不是标量数组。。。但是';img&x27;isn';t在我的代码中用作变量名

Python img不是numpy数组,也不是标量数组。。。但是';img&x27;isn';t在我的代码中用作变量名,python,opencv,houghlinesp,Python,Opencv,Houghlinesp,我试图在视频中找到垂直线。Python 2.7和OpenCV 3。 我正在使用背景减法,然后应用Canny边缘检测过滤器。 我已经能够将HoughLinesP方法应用于单个图像,但需要将其扩展到视频 我在运行一组基本代码(我认为这与下面的行“a,b,c=hlines.shape”对应)时收到此错误: 任何建议都将不胜感激。@Jeru Luke的回答似乎成功了。 我把函数调用搞错了 正如我所理解的问题。。。我试图使用原始视频捕获变量(文件路径)作为我正在解析的数组。此原始变量不是数组(它是一个文本

我试图在视频中找到垂直线。Python 2.7和OpenCV 3。
我正在使用背景减法,然后应用Canny边缘检测过滤器。
我已经能够将HoughLinesP方法应用于单个图像,但需要将其扩展到视频

我在运行一组基本代码(我认为这与下面的行“a,b,c=hlines.shape”对应)时收到此错误:


任何建议都将不胜感激。

@Jeru Luke的回答似乎成功了。 我把函数调用搞错了

正如我所理解的问题。。。我试图使用原始视频捕获变量(文件路径)作为我正在解析的数组。此原始变量不是数组(它是一个文本字符串)。。。回想起来,这使得错误更有意义。 我将引发错误的行更改为:

cv2.line(frame, (hlines[k][0][0], hlines[k][0][1]), (hlines[k][0][2], hlines[k][0][3]), (0,255,0), 3, cv2.LINE_AA)  `

这允许我遍历数组。

如果您检查了出现错误的函数调用,您将看到
img
cv2.line
的第一个参数的名称。查看作为该参数传递的对象。另外,学习查找文档。尝试
cv2.line(frame,(hlines[k][0][0],hlines[k][0][1]),(hlines[k][0][2],hlines[k][0][3]),(0255,0),3,cv2.line_AA)
`@user2357112:没有理由这么讨厌。一句简单的“嘿,你给函数传递了错误的东西”就足够了,不会让人觉得你是个混蛋。@Jeru Luke:谢谢!那很有帮助!你为什么不给出一个详细的答案呢?你可以选择验证你的答案。你说我必须先等几天。(现在要找出下一个错误“AttributeError:'NoneType'对象没有属性…”出现在哪一行?如果我取消注释第26行(bkgnd=cv2…)并添加两个其他语句…可能需要一个全新的问题,因为代码需要调整一点(额外的函数调用).我将进行一些挖掘,但可能很快会在这里发布另一个问题。
import cv2
import numpy as np
import imutils 
import argparse

np.set_printoptions(threshold=np.inf) #to print entire array, no truncation

ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video", help = "/home/odroid/Desktop/python_scripts/test/test_images/Edited_Foam_Dispense_Short.mp4")

args = vars(ap.parse_args())

LOWER_BOUND = 55   #cv2.threshold()
UPPER_BOUND = 255  #cv2.threshold()

CANNY_LOWER_BOUND = 10  #cv2.Canny()
CANNY_UPPER_BOUND = 250 #cv2.Canny()

MIN_LINE_LENGTH = 2  #HoughLinesP()
MAX_LINE_GAP = 100     #HoughLinesP() 
HOUGH_THETA = np.pi/180 #HoughLinesP() angle resolution of the accumulator, radians
HOUGH_THRESHOLD = 25 #HoughLinesP() 
HOUGH_RHO = 1         #HoughLinesP() rho, Distance resolution of the accumulator, pixels


#bkgnd = cv2.bgsegm.createBackgroundSubtractorMOG()
camera = cv2.VideoCapture('/home/odroid/Desktop/python_scripts/test/test_images/Edited_Foam_Dispense_Short.mp4')

# if a video path was not supplied, grab the reference
# to the webcam
if not args.get("video", False):
    camera = cv2.VideoCapture(0)
    print("Video file not grabbed")

# otherwise, grab a reference to the video file
else:
    camera = cv2.VideoCapture(args["video"])

while(True):
    (grabbed, frame) = camera.read()

# if we are viewing a video and we did not grab a frame,
# then we have reached the end of the video
    if args.get("video") and not grabbed:
        break

# resize the frame, blur it, and convert it to the HSV
# color space
    frame = imutils.resize(frame, width=600)

    canny_threshold = cv2.Canny(frame, CANNY_LOWER_BOUND, CANNY_UPPER_BOUND)    
    hlines = cv2.HoughLinesP(canny_threshold, HOUGH_RHO, HOUGH_THETA, MIN_LINE_LENGTH, MAX_LINE_GAP)

    a,b,c = hlines.shape

    for k in range(a):
        #pretty sure the issue is somewhere here
        cv2.line(camera, (hlines[k][0][0], hlines[k][0][1]), (hlines[k][0][2], hlines[k][0][3]), (0,255,0), 3, cv2.LINE_AA)



cv2.imshow("Frame", frame)
cv2.imshow('image', canny_threshold)





if cv2.waitKey(1) & 0xFF == ord('q'):
    break

camera.release()
cv2.destroyAllWindows()
cv2.line(frame, (hlines[k][0][0], hlines[k][0][1]), (hlines[k][0][2], hlines[k][0][3]), (0,255,0), 3, cv2.LINE_AA)  `