Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting errors while detecting circle

I want to detect blue circles and it's center from the video captured using my webcam. That's why I formed the following code given below: (I am using OpenCV 3.1.0 and PyCharm as an IDE and Anaconda Python 2.7 for 64 bits)

    import cv2
    import numpy as np

    cap = cv2.VideoCapture(0)
    while(True):
        frame, _ = cap.read()
        # blurring the frame that's captured
        frame_gau_blur = cv2.GaussianBlur(frame, (3, 3), 0)
        # converting BGR to HSV
        hsv = cv2.cvtColor(frame_gau_blur, cv2.COLOR_BGR2HSV)
        # the range of blue color in HSV
        lower_blue = np.array([110, 50, 50])
        higher_blue = np.array([130, 255, 255])
        # getting the range of blue color in frame
        blue_range = cv2.inRange(hsv, lower_blue, higher_blue)
        # getting the V channel which is the gray channel
        blue_s_gray = blue_range[::2]
        # applying HoughCircles
        circles = cv2.HoughCircles(blue_s_gray, cv2.HOUGH_GRADIENT, 1, 10, 100, 30, 5, 50)
        circles = np.uint16(np.around(circles))
        for i in circles[0,:]:
            # drawing on detected circle and its center
            cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
            cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
         cv2.imshow('circles', frame)
        k = cv2.waitKey(5) & 0xFF
        if k == 27:
        break
    cv2.destroyAllWindows()

But after running the code I get an error. And the error is:

OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cv::cvtColor, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp, line 7935 Traceback (most recent call last): File "C:/Users/Meliodas/PycharmProjects/OpenCV_By_Examples/code_tester.py", line 10, in <module> hsv = cv2.cvtColor(frame_gau_blur, cv2.COLOR_BGR2HSV) cv2.error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp:7935: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cv::cvtColor

How do i solve this error? Thanks a lot in advance, for being so kind to help me.

click to hide/show revision 2
retagged

updated 2016-08-08 05:35:36 -0600

berak gravatar image

Getting errors while detecting circle

I want to detect blue circles and it's center from the video captured using my webcam. That's why I formed the following code given below: (I am using OpenCV 3.1.0 and PyCharm as an IDE and Anaconda Python 2.7 for 64 bits)

    import cv2
    import numpy as np

    cap = cv2.VideoCapture(0)
    while(True):
        frame, _ = cap.read()
        # blurring the frame that's captured
        frame_gau_blur = cv2.GaussianBlur(frame, (3, 3), 0)
        # converting BGR to HSV
        hsv = cv2.cvtColor(frame_gau_blur, cv2.COLOR_BGR2HSV)
        # the range of blue color in HSV
        lower_blue = np.array([110, 50, 50])
        higher_blue = np.array([130, 255, 255])
        # getting the range of blue color in frame
        blue_range = cv2.inRange(hsv, lower_blue, higher_blue)
        # getting the V channel which is the gray channel
        blue_s_gray = blue_range[::2]
        # applying HoughCircles
        circles = cv2.HoughCircles(blue_s_gray, cv2.HOUGH_GRADIENT, 1, 10, 100, 30, 5, 50)
        circles = np.uint16(np.around(circles))
        for i in circles[0,:]:
            # drawing on detected circle and its center
            cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
            cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
         cv2.imshow('circles', frame)
        k = cv2.waitKey(5) & 0xFF
        if k == 27:
        break
    cv2.destroyAllWindows()

But after running the code I get an error. And the error is:

OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cv::cvtColor, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp, line 7935 Traceback (most recent call last): File "C:/Users/Meliodas/PycharmProjects/OpenCV_By_Examples/code_tester.py", line 10, in <module> hsv = cv2.cvtColor(frame_gau_blur, cv2.COLOR_BGR2HSV) cv2.error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp:7935: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cv::cvtColor

How do i solve this error? Thanks a lot in advance, for being so kind to help me.

click to hide/show revision 3
retagged

updated 2016-08-08 05:36:08 -0600

berak gravatar image

Getting errors while detecting circle

I want to detect blue circles and it's center from the video captured using my webcam. That's why I formed the following code given below: (I am using OpenCV 3.1.0 and PyCharm as an IDE and Anaconda Python 2.7 for 64 bits)

    import cv2
    import numpy as np

    cap = cv2.VideoCapture(0)
    while(True):
        frame, _ = cap.read()
        # blurring the frame that's captured
        frame_gau_blur = cv2.GaussianBlur(frame, (3, 3), 0)
        # converting BGR to HSV
        hsv = cv2.cvtColor(frame_gau_blur, cv2.COLOR_BGR2HSV)
        # the range of blue color in HSV
        lower_blue = np.array([110, 50, 50])
        higher_blue = np.array([130, 255, 255])
        # getting the range of blue color in frame
        blue_range = cv2.inRange(hsv, lower_blue, higher_blue)
        # getting the V channel which is the gray channel
        blue_s_gray = blue_range[::2]
        # applying HoughCircles
        circles = cv2.HoughCircles(blue_s_gray, cv2.HOUGH_GRADIENT, 1, 10, 100, 30, 5, 50)
        circles = np.uint16(np.around(circles))
        for i in circles[0,:]:
            # drawing on detected circle and its center
            cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),2)
            cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
         cv2.imshow('circles', frame)
        k = cv2.waitKey(5) & 0xFF
        if k == 27:
        break
    cv2.destroyAllWindows()

But after running the code I get an error. And the error is:

OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cv::cvtColor, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp, line 7935 Traceback (most recent call last): File "C:/Users/Meliodas/PycharmProjects/OpenCV_By_Examples/code_tester.py", line 10, in <module> hsv = cv2.cvtColor(frame_gau_blur, cv2.COLOR_BGR2HSV) cv2.error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\color.cpp:7935: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cv::cvtColor

How do i solve this error? Thanks a lot in advance, for being so kind to help me.