Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:40:45+00:00 2026-06-07T00:40:45+00:00

I think I’ve figured out the problem. I’m using a IP webcam stream, doing

  • 0

I think I’ve figured out the problem. I’m using a IP webcam stream, doing a canny edge and hough transform. Then showing the overlayed transform and the original image. So pretty much just looks like the normal web cam but the horizontal lines are highlighted.
and I’m looking for horizontal lines in the image. It works just fine as long as there are horizontal lines in it. If I start the cam and there aren’t any horizontal lines, I get the error:

 Traceback (most recent call last):
  File "/home/Desktop/hough.py", line 16, in <module>
  for line in lines[0]:
  TypeError: 'NoneType' object has no attribute '__getitem__'

Here’s the whole code. I’m very new to python and opencv so I’m not sure how to fix this. I’d like it to just show the blank image when there aren’t any horizontal lines so I can have a continuous stream.

Also my next task is to try and save the images into a video. Any help on that part would be greatly appreciated. thanks!

import cv2
import urllib
import math


cv2.namedWindow('edge')


while True:
    urllib.urlretrieve("http://192.168.5.1:8080/shot.jpg", 'cam.jpg')
    img = cv2.imread('cam.jpg')
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 80, 120, apertureSize=3)

    lines = cv2.HoughLinesP(edges, 1, math.pi/2, 2, None, 30, 1)
    for line in lines[0]:
            pt1 = (line[0],line[1])
            pt2 = (line[2],line[3])
            cv2.line(img, pt1, pt2, (0,0,255), 3)

    cv2.imwrite("road2.jpg", img)
    cv2.imshow('edge', img)
    ch = cv2.waitKey(5)
    if ch == 27:
            break
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:40:48+00:00Added an answer on June 7, 2026 at 12:40 am

    Apparently cv2.HoughLinesP returns None when there are no lines.

    On line 16, you try to access lines[0], which actually calls lines.__getitem__. As lines is of type NoneType, it doesn’t have a __getitem__ method.

    To solve the problem, you can for example check that lines is not None before accessing its items:

    if lines:
        for line in lines[0]
            [...]
    

    (note that it will also check that lines is not an empty list)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Think about doing this: import matplotlib.pyplot as plt plt.plot(x_A,y_A,'g--') plt.plot(x_B,y_B,'r-o') plt.show() How would you
Think my problem is I am trying to sum a count in the same
Think you are the proud owner of Facebook, then which data you want to
I think there is a logical / mathematical solution to this problem and I
I think that I have a quite strange question. I am using a class
I think this is a relatively simple problem. I wish to obtain some functionality
I think this should be an easy problem to solve, however its turned into
I think most people here understand the importance of fully automated builds. The problem
I think there is a problem with my ImageView. i created a gallery, where
I think this is a simple SQL query problem, but I am just not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.