Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using -json_port 8070 #8104

Closed
lingogogo opened this issue Sep 22, 2021 · 2 comments
Closed

using -json_port 8070 #8104

lingogogo opened this issue Sep 22, 2021 · 2 comments

Comments

@lingogogo
Copy link

lingogogo commented Sep 22, 2021

Thank a lot in advance.

i use -json_port to send the data to website http://localhost:8070
But now i want to transfer the data to my ROS system.
i have some problem for this

#!/usr/bin/python2

import urllib
import json
import ssl
import json
import rospy
from std_msgs.msg import ColorRGBA


ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

frame_now = 0
#website location
serviceurl = 'http://127.0.0.1:8070'

pub1 = rospy.Publisher('data_from_yolov3' , ColorRGBA , queue_size = 10)


def talker():
    rospy.init_node('get_data_yolo',anonymous = True)
    rate = rospy.Rate(10)

    while not rospy.is_shutdown():
        url = serviceurl
        print('Retrieving', url)

        uh = urllib.urlopen(url)
        data = uh.read().decode()
        print('Retrieved')

        try:
            js = json.loads(data)
           get_data(js)
        except:
            js = None

        if not js or 'status' not in js or js['status'] != 'OK':
             print('==== Failure To Retrieve ====')
             print(data)
 


#functtion
def get_data(distros_dict):
    json_to_variable = []
    global frame_id, class_id,x,y,width,height
    # For every frame.
    for distro in distros_dict:
        filename = distro['filename']
        if len(distro['objects']) != 0:
            # For every detection.
            for obj in range(len(distro['objects'])):
                # Get values.
                frame_id = distro['frame_id']
                frame_now = frame_now + 1
                class_id = distro['objects'][obj]["class_id"]
                x = distro['objects'][obj]["relative_coordinates"]["center_x"]
                y = distro['objects'][obj]["relative_coordinates"]["center_y"]
                width = distro['objects'][obj]["relative_coordinates"]["width"]
                height = distro['objects'][obj]["relative_coordinates"]["height"]
                confidence = distro['objects'][obj]["confidence"]
                # width640
                x = x*1280
                # height480
                y = y*720
                # detect_image real height and width
                width =  width * 1280
                height = height * 720
                # deal with the data
                # And print them.
                #######################
                # publish data
                pub1.publish(x,y,width,height)
                #######################
                print(frame_id, class_id, x, y, width, height, confidence)
              
if __name__ == '__main__' :
try:
talker()
except rospy.ROSInterruptException:
pass
#over

terminal line
Retrieving from 'http://127.0.0.1:8070'

so it cannot open the url.
if anyone can teach me how to solve the problem.

@AlexeyAB
Copy link
Owner

If you want to use ROS with YOLO, try these repositories / pull requests:

@lingogogo
Copy link
Author

Thank for your help , i will try this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants