Closed Arsalan66 closed 4 years ago
what are the steps that i'm doing wrong and what can i do to rectify them?
I do not think the problem is related to this repo.
If you are sure callbacks are executed, you can add some print functions to help you debug, I don't quite see any issue in the code you provided.
Thanks for the kind response basically I want to implement IBVS via colour detection schemes suppose if I do this in GAAS framework, what are the subscribers that I would have to keep in mind to manipulate the camera, I'll be grateful for your kind response
i ALSO usec cv2.imshow to check
Can you confirm that you have published information by using the “rostopic” command? Or can you display your published Image msg in ”rviz“?
i made a custom publisher but in case of manipulating the drone's camera i'm unsure about the subscribers
sir can i have your mail, i want to discuss this small issue with you
We prefer to answer questions at GitHub issue, This can help other people with the same problem.
I don't see any issue in the code you provided. So if you can provide the message you printed using the rostopic command or the rviz screenshot will help me determine the problem.
You can see the usage about rostopic and rviz in GAAS tutorial 1 and GAAS tutorial 2.
Ok sir , I'll provide as soon as possible , thanks for the kind response
import rospy, cv2
import numpy as np from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError
bridge = CvBridge() def tracking_ball(mask,cv_image):
black_image = np.zeros(cv_image.shape, np.uint8)
_,contours,_ = cv2.findContours(mask,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
if cv2.contourArea(c) > 1000:
# find radius
((x,y),r) = cv2.minEnclosingCircle(c)
# find the cx, cy of the contour
m = cv2.moments(c)
cx = -1
cy = -1
if m['m00'] != 0:
cx = int(m['m10']/m['m00'])
cy = int(m['m01']/m['m00'])
# draw the contours
cv2.drawContours(cv_image,[c],-1,(0,0,255),1)
cv2.drawContours(black_image,[c],-1,(0,0,255),1)
# draw a circle around the ball
cv2.circle(cv_image,(cx,cy),int(r),(255,0,0),1)
cv2.circle(black_image,(cx,cy), int(r),(255,0,0),1)
# draw the center of the ball
cv2.circle(cv_image,(cx,cy),5,(0,0,0),-1)
cv2.circle(black_image,(cx,cy),5,(0,0,0),-1)
# show images
#img_join = np.concatenate((cv_image,black_image),axis=1)
cv2.imshow('cv_image', cv_image)
cv2.imshow('black_image',black_image)
def create_mask(hsv_image): lower_hsv = (30,100,100) upper_hsv = (50,255,255) mask = cv2.inRange(hsv_image,lower_hsv,upper_hsv) return mask
def hi_callback(ros_image): print 'got an image' global bridge cv_image = bridge.imgmsg_to_cv2(ros_image, "bgr8") hsv = cv2.cvtColor(cv_image,cv2.COLOR_BGR2HSV) mask=create_mask(hsv) tracking_ball(mask,cv_image) rospy.loginfo('frame received!') cv2.waitKey(5)
if name == 'main':
# create a node
rospy.init_node('tennis_ball_listener_node',anonymous=True)
# create the subscriber
rospy.Subscriber('/gi/simulation/left/image_raw',Image,hi_callback)
# start a loop
rospy.spin()
@hddgi sir, this is my code , i want to process video published by '/gi/simulation/left/image_raw' topic, however the output was the same that frames are being received but not shown, what might i be doing wrong?
Sir, another method that i have in mind is to manipulate the publisher, where might be it's file located and is it a good idea or not?
here's the publisher that i used for testing
import numpy as np import cv2 from std_msgs.msg import String from sensor_msgs.msg import Image import rospy import sys from cv_bridge import CvBridge, CvBridgeError
bridge = CvBridge()
def talker(): pub = rospy.Publisher('tennis_ball_image', Image, queue_size=10) rospy.init_node('talker', anonymous=True)
video_capture = cv2.VideoCapture('video/tennis-ball-video.mp4')
rate = rospy.Rate(1)
while not rospy.is_shutdown():
# read a frame
ret, frame = video_capture.read()
#frame = cv2.resize(frame,None,fx=0.25,fy=0.25,interpolation=cv2.INTER_CUBIC)
if ret:
# publish frame in data
frame_msg = bridge.cv2_to_imgmsg(frame,'bgr8')
pub.publish(frame_msg)
rospy.loginfo('Sending frame')
rate.sleep()
video_capture.release()
cv2.destroyAllWindows()
if name == 'main': try: talker() except rospy.ROSInterruptException: pass
Prerequisites
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
Issue Template
Context
Please provide any relevant information about your setup.
Expected Behavior
Please describe the behavior you are expecting. I want to process videos based on drone's camera
Current Behavior
What is the current behavior? I have created a publisher and subscriber to video frames on a custom video and it runs perfectly however when i subscribe to topics related to camera, it doesn't show up anything although my program says that frames are being received
Screenshots
If applicable, add screenshots to help explain your problem. here's a screenshot which runs my code here's the output of custom video
Failure Logs
this is the topic that i subscribe to for drone, it says frames are being recieved but doesn't show anything i made a custom drone:
Copy console log and paste it here.