Ask Your Question

arp1561's profile - activity

2021-05-11 05:33:08 -0600 received badge  Famous Question (source)
2021-02-06 08:28:04 -0600 received badge  Notable Question (source)
2020-05-21 05:48:27 -0600 received badge  Popular Question (source)
2019-11-18 02:47:58 -0600 received badge  Famous Question (source)
2019-08-11 08:47:56 -0600 received badge  Notable Question (source)
2018-09-18 21:28:46 -0600 received badge  Notable Question (source)
2018-08-27 11:33:26 -0600 received badge  Famous Question (source)
2018-08-18 04:27:58 -0600 received badge  Popular Question (source)
2018-05-10 08:01:34 -0600 received badge  Famous Question (source)
2018-04-26 03:57:08 -0600 received badge  Popular Question (source)
2018-01-11 05:00:34 -0600 received badge  Notable Question (source)
2017-09-04 04:58:53 -0600 received badge  Notable Question (source)
2017-08-10 01:38:40 -0600 received badge  Popular Question (source)
2017-07-18 18:30:42 -0600 received badge  Popular Question (source)
2016-03-13 09:08:30 -0600 asked a question Detecting Blue Color in this image

This image was taken from a Quad-Copter. I need to detect the blue color that the guy in this picture is wearing.

It would be very helpful if you guys would try to guide me. I am also attaching the code that i used. The hsv range never seems to be correct.

import cv2
import numpy as np
from matplotlib import pyplot as plt

frame = cv2.imread("a.jpeg")
img = frame
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
lower_blue= np.array([78,158,124])
upper_blue = np.array([138,255,255])

mask = cv2.inRange(img,lower_blue,upper_blue)

img,cnts,hie = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
cv2.drawContours(frame,cnts,-1,(0,255,0),3)

cv2.imshow("Frame",frame)
cv2.waitKey(0)

The image

2015-11-24 12:43:21 -0600 commented question Contour approximation not working correctly

convexHull() shows 7,8 points for a rectangle :P I wont be able to detect a rectangle with that.

Please anyone :\

2015-11-24 11:44:53 -0600 commented question Contour approximation not working correctly

And using just these 4 points above how will i determine if it's a circle? It could be a square or a rectangle?

2015-11-24 11:44:18 -0600 commented question Contour approximation not working correctly

I actually dont want four points. I used the same technique for a similar type of rectangle with defects and it gives 4 points at 4 corners. That would be sufficient to know that it is a rectangle. But what if I want contour lines and not just points? How will I do that?

2015-11-24 08:20:47 -0600 asked a question Contour approximation not working correctly

I have a white circle with black lines going from either side(as shown in the picture). The problem is that when I use the contour approx method, it just outputs points around the image. rather than a whole complete circle

GNU nano 2.2.6 File: test.py Modified

                   import cv2

                   img = cv2.imread("circ.jpeg")
                   canny = cv2.Canny(img,150,300)
                   ima,cnts,hie= cv2.findContours(canny,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)


                   cnt = cnts[0]
                   epsilon = 0.1*cv2.arcLength(cnt,True)
                   approx = cv2.approxPolyDP(cnt,epsilon,True)
                   cv2.drawContours(img,approx,-1,(0,255,0),3)
                   cv2.imshow("img",img)


                   cv2.waitKey(0)
                   cv2.destroyAllWindows()

This is the image of the circle. This is how it comes.

2015-11-24 08:07:01 -0600 commented question findContours not working properply

I've linked the black and white image also

2015-11-24 08:06:48 -0600 commented question findContours not working properply

Well, even if i create an image via paint. This problem still persists.

2015-11-24 07:36:16 -0600 commented question findContours not working properply

@LorenaGdL There you go!

2015-11-24 07:11:19 -0600 asked a question findContours not working properply

I am using findContours on a simple white circle i created on a paint application with a black back ground. The problem is that while the tutorials tell me that there should be only one contour surrounding that circle, when i output the contours, there are 2 different points.

Due to this reason, i am not able to use contour approx method.

Can anyone help me with this?

Thanks in Advance!

                    import cv2
                    import numpy as np

                    img = cv2.imread("url.png")

                    canny = cv2.Canny(img,0,0)

                    imgs,cnts,hie = cv2.findContours(canny,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

                    cv2.namedWindow("img",cv2.WINDOW_NORMAL)

                    cnt = cnts[1]

                   epsilon = 0.1*cv2.arcLength(cnt,True)
                   approx = cv2.approxPolyDP(cnt,epsilon,True)

                   cv2.drawContours(img,approx,-1,(0,255,0),3)

                   cv2.imshow("img",img)

                  cv2.waitKey(0)
                  cv2.destroyAllWindows()

This is the original image(/upfiles/14483724218429244.png) This is the editied image for approximation(/upfiles/14483724673701482.png)

The black and white image/(/upfiles/14483740423517343.jpeg)

2015-11-23 04:27:48 -0600 asked a question Use contours in a video?

This is the program I use for drawing all the contours around an image

                import numpy as np
                import cv2
                im = cv2.imread('test.jpg')
                imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
                ret,thresh = cv2.threshold(imgray,127,255,0)
                im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

For drawing contours in a video, I use this program.

                import cv2
                cap = cv2.VideoCapture(0)
                while True:
                          ret,frame=cap.read()
                          gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
                          ret,thresh = cv2.threshold(gray,140,255,0)
                          image,contours,hie = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
                          frame = cv2.drawContours(frame, contours, 3, (0,255,0), 3)
                          cv2.imshow("vid",frame)
                          if cv2.waitKey(1) & 0xFF == ord('q'):
                                           break

cap.release() cv2.destroyAllWindows()

Now the problem is that when I run the second program, there are multiple errors

1-> Need more than 2 values to unpack.

2-> When I remove the image parameter from the findContours(), and try to display, it still gives me an error.

Can someone please explain to me why this is happening?

Thanks in advance! :)

2015-11-21 09:57:58 -0600 asked a question What are all the three parameters of cv2.findContours() and it's output?
           1 - cv2.findContours(thresh, 1, 2) 
          2 - image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)

Can someone please tell me what the 2 parameters in this function mean?? Why we used 1 and 2 in the First example and why we wrote that much for the second one?

Thanks in Advance :) P.S. I am a beginner

2015-11-21 09:37:35 -0600 asked a question findcontours() output doubt
    image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

In this line i understand the meaning of image and contours. but what is hierarchy?? Could anyone explain?

Thanks in advance! :) P.S. I am a beginner.

2015-11-19 02:46:46 -0600 commented question What are all the parameters of bitwise_and?

frame and mask have been created above.

2015-11-19 02:46:13 -0600 asked a question What are all the parameters of bitwise_and?

I am an opencv beginner but the documentation hasn't properly explained why we use the three parameters?

                           res = cv2.bitwise_and(frame,frame, mask= mask)

this is the specific line i did not understand.

If anyone can help, that would be great!

Thanks in advance! :D

2015-10-31 03:02:42 -0600 commented answer Whyare all the images in uint8 data type?

Thank You so very much!! :) Helped me out a lot!! :D

2015-10-31 03:00:58 -0600 received badge  Enthusiast
2015-10-30 05:32:10 -0600 commented answer Whyare all the images in uint8 data type?

Well, Thanks a lot for this amazing answer I have totally understood that uint8 is used since the max value of RGB/BGR channels are 0,255 and uint8 has that range. Got that

But, Why would have an image have another data type that is more than uint8? Since the BGR/RGB channels support only 0,255 values??

Thanks in advance! :)

2015-10-29 07:14:08 -0600 asked a question Whyare all the images in uint8 data type?

I was just learning OpenCV and I wondered why all the images have a unint8 data type?

I understand what a uint8 data type is, but how does it apply here?

I hope you can help me! Thanks!

2015-10-28 08:28:49 -0600 received badge  Editor (source)
2015-10-28 08:28:10 -0600 asked a question How does np.zeros() create a black background?

I am creating a very simple line drawing program. The problem is that i am still in the learning stage and I jsut stumbled across a problem.

import numpy as np import cv2

img = np.zeros((512,512,3), np.uint8)

img = cv2.line(img,(0,0),(511,511),(255,0,0),5)

how does np.zeros((512,512,3), np.uint8) create a black back ground? What if i want to create a red or a green background? And also, what does these 2 parameters mean?

I hope this answers my problem! Thanks!! :)

2015-10-27 08:18:45 -0600 asked a question Problem with OpenCV 3 - Image output too large

I try a very simple program which reads the image and outputs it. The problem I am having is that the resultant image outputted by the cv2.imshow() is very very large in size. I have tried ccv2.resizeWindow() with the parameters but it does not seem to work. I really hope you guys can help me! Thanks in advance! :)

import cv2
import numpy as np
img = cv2.imread('messi.jpg')
cv2.imshow('img',img)

cv2.waitKey(0)
cv2.destroyAllWindows()
2015-10-24 03:55:41 -0600 asked a question OpenCV video freezes

I just installed opencv 3-dev. I then ran a simple code of a normal video capture which outputs the video taken from the webcam. But as soon as the program window opens the video freezes. It sometimes runs and sometimes hangs. I currently have found no solution. My code is as follows

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # Display the resulting frame
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

This is the code! I hope you help me! Thanks in advance!! :)