2020-10-21 07:28:47 -0600
| received badge | ● Popular Question
(source)
|
2016-07-28 05:48:47 -0600
| received badge | ● Supporter
(source)
|
2016-07-28 05:48:44 -0600
| received badge | ● Scholar
(source)
|
2016-07-28 05:48:39 -0600
| commented answer | had problem when convert the image from BGR to HSV Hi berak, Thank you so much! Your idea is totally work for me! |
2016-07-28 01:28:16 -0600
| commented answer | had problem when convert the image from BGR to HSV |
2016-07-28 01:20:28 -0600
| commented answer | had problem when convert the image from BGR to HSV wow! cool! Let me try it. So the edited part just need simply add into my program or I have to write a new program to do? |
2016-07-28 00:27:08 -0600
| commented answer | had problem when convert the image from BGR to HSV Haha, ok. Thank you!
And one more question, since my converting was correct. But when I try to do the cv2.inRange , I cannot do the mask very well. due to the lower and upper value was not set so good.
So do you know any way can find out the Blue, Green or Red color's range? |
2016-07-28 00:17:51 -0600
| received badge | ● Editor
(source)
|
2016-07-28 00:16:50 -0600
| commented answer | had problem when convert the image from BGR to HSV Hi berak,
So which is mean that my converting part was no problem right? |
2016-07-28 00:05:21 -0600
| asked a question | had problem when convert the image from BGR to HSV Hi everyone, I'm just a beginner in OpenCV. I'm trying to find the green ball's center point in the image.
But when I try to convert the image from BGR to HSV the shows image result will be change to another kind of color instead of the orignal image.
This is the result image after the convertion:
Base on my simple understand it should not show this image results after the BGR to HSV.
So does anyone know what's the problem cause my problem?
Thank you! Follow is my whole program: #!/usr/bin/env python
# coding=utf-8
import sys
import rospy
import cv2
#import cv
import argparse
import numpy as np
from std_msgs.msg import String
from sensor_msgs.msg import Image
import std_srvs.srv
def image_processing (color):
#image_src = cv2.imread('home/ros_ws/src/baxter_examples/ColorBalls.jpg',0)
print ("deciding color...............")
if color == "blue":
lower = (86,31,4)
upper = (220,88,50)
if color == "green":
lower = (29,30,20)
upper = (64,255,255)
if color == "red":
lower = (17,15,100)
upper = (50,56,200)
print color
image_hsv = cv2.cvtColor(image_resized,cv2.COLOR_BGR2HSV)
cv2.imshow("or_image",image_hsv)
cv2.waitKey(0)
cv2.destroyAllWindows()
image_mask = cv2.inRange(image_hsv,lower,upper)
#cv2.imshow("or_image",image_mask)
#cv2.waitKey(0)
image_mask = cv2.erode(image_mask, None, iterations=2)
image_mask = cv2.dilate(image_mask, None, iterations=2)
cv2.imshow("or_image",image_mask)
cv2.waitKey(0)
print ("end maskingg")
print ("finding center.........")
contours, hierarchy = cv2.findContours(image_mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
if contours is None:
print ("cont is None")
print ("len.........")
print len(contours)
if len(contours) > 0:
print ("############################")
print len(contours)
c = max (contours,key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
print center
if radius > 1:
cv2.circle(image_resized, (int(x), int(y)), int(radius),(0, 255, 255), 2)
cv2.circle(image_resized, center, 2, (0, 0, 255), -1)
def main():
global ball_color
global image_src
global image_resized
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt, description=main.__doc__)
parser.add_argument(
'-c','---color', dest='color',choices=['blue','green','red'], required=True,
help= "the ball color to pick up",
)
args=parser.parse_args()
print ("Initializing...........................................")
rospy.init_node("ylj_ballposition",anonymous=True)
#image_src = cv2.imread('/home/ros_ws/src/baxter_examples/scripts/ColorBalls.JPG')
print ("reading the image")
image_src = cv2.imread('Balls.JPG')
print ("readed..............")
if image_src is None:
print ("the image read is None............")
#print ("show the image............")
#cv2.imshow("or_image",image_src)
#cv2.waitKey(0)
print image_src.shape
print ("resizing........")
image_resized = cv2.resize(image_src,(400,300),interpolation = cv2.INTER_AREA)
print image_resized.shape
print ("resized........")
#cv2.imshow("or_image",image_resized)
#cv2.waitKey(0)
print ("start image processing......")
image_processing(args.color)
cv2.imshow("image_processed",image_resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__=='__main__':
main()
|
2016-07-27 04:51:13 -0600
| commented question | using OpenCV to find the seletected ball's center in python Hi berak,
I follow you idea and change the image reading path, then my problem was solved.
Thank you for your advice. |
2016-07-27 04:37:07 -0600
| commented question | using OpenCV to find the seletected ball's center in python oh, I found the method. It's just
if image_src is None : print ("the image read is None............")
And the showing result shows that it is None. It's that mean I didn't read the image? |
2016-07-27 04:33:22 -0600
| commented question | using OpenCV to find the seletected ball's center in python Sorry....I had no idea about how to check the None or np.shape(img)==(). Would you mind teach me how to check it? or any website can find it? |
2016-07-27 04:23:34 -0600
| commented question | using OpenCV to find the seletected ball's center in python I try add the : print ("Initializing...........................................")
rospy.init_node("ylj_ballposition",anonymous=True)
image_src = cv2.imread('home/ros_ws/src/baxter_examples/ColorBalls.jpg')
**print ("read the image....")**
Then will shows: Initializing...........................................
read the image....
deciding color...............
blue
OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp, line 3959
Traceback (most recent call last):
The rest of error message still same. |
2016-07-27 04:19:45 -0600
| commented question | using OpenCV to find the seletected ball's center in python So what kind of print checks should I use? I kind of new in OpenCV would you mind give more detail things?Thank you |
2016-07-27 04:15:13 -0600
| asked a question | using OpenCV to find the seletected ball's center in python Hi everyone, I'm a beginner and trying to use the basic OpenCV to find the choose color ball's center x,y value from the image. But When I try to run my program there had some error happen but I had no idea what's wrong in my program. Can anyone help me? Follow is my progam: #!/usr/bin/env python
# coding=utf-8
import sys
import rospy
import cv2
import cv
import argparse
import numpy as np
from std_msgs.msg import String
from sensor_msgs.msg import Image
import std_srvs.srv
def image_processing (color):
#image_src = cv2.imread('home/ros_ws/src/baxter_examples/ColorBalls.jpg',0)
print ("deciding color...............")
if color == "blue":
lower = (86,31,4)
upper = (220,88,50)
if color == "green":
lower = (29,86,6)
upper = (64,255,255)
if color == "red":
lower = (17,15,100)
upper = (50,56,200)
print color
image_hsv = cv2.cvtColor(image_src,cv2.COLOR_BGR2HSV)##################
image_mask = cv2.inRange(image_hsv,lower,upper)
image_mask = cv2.erode(image_mask, None, iterations=2)
image_mask = cv2.dilate(image_mask, None, iterations=2)
print ("end maskingg")
print ("finding center.........")
contours,hierarchy = cv2.findContours(image_mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[-2]
if len(contours) > 0:
c = max (contours,key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
print center
if radius > 1:
cv2.circle(image_src, (int(x), int(y)), int(radius),(0, 255, 255), 2)
cv2.circle(image_src, center, 2, (0, 0, 255), -1)
def main():
global ball_color
global image_src
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt, description=main.__doc__)
parser.add_argument(
'-c','---color', dest='color',choices=['blue','green','red'], required=True,
help= "the ball color to pick up",
)
args=parser.parse_args()
print ("Initializing...........................................")
rospy.init_node("ylj_ballposition",anonymous=True)
image_src = cv2.imread('home/ros_ws/src/baxter_examples/ColorBalls.jpg',1)
image_processing(args.color)
cv2.imshow("image_processed",image_src)
if __name__=='__main__':
main()
This is the error message show: Initializing...........................................
deciding color...............
blue
OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp, line 3959
Traceback (most recent call last):
File "/home/leddar/ros_ws/src/baxter_examples/scripts/ylj/ylj_imgball.py", line 101, in <module>
main()
File "/home/leddar/ros_ws/src/baxter_examples/scripts/ylj/ylj_imgball.py", line 91, in main
image_processing(args.color)
File "/home/leddar/ros_ws/src/baxter_examples/scripts/ylj/ylj_imgball.py", line 36, in image_processing
image_hsv = cv2.cvtColor(image_src,cv2.COLOR_BGR2HSV)##################
cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/color.cpp:3959: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor
|