Exemple #1
0
    def __init__(self):
        self.image_sub = rospy.Subscriber("/xtion/rgb/image_raw", Image, self.image_callback)
        self.label_sub = rospy.Subscriber("/hearts/obj_rec/label", String, self.label_callback)
        self.camera_info_sub = rospy.Subscriber("/camera_info", CameraInfo, self.camera_info_callback)

        self.listener = TransformListener()
                
        self.reference_frame = rospy.get_param("reference_frame", "")
        
        if not self.listemer.frameExists(self.reference_frame):
            rospy.logerr("invalid reference frame: " + self.reference_frame)
            
        self.camera_frame = rospy.get_param("camera_frame", "")

        if not self.listemer.frameExists(self.camera_frame):
            rospy.logerr("invalid camera frame: " + self.camera_frame)
            
        self.temp_file_path = "/tmp/obj_rec_1/"
        
        self.bridge = CvBridge()
        self.match = re.compile("name': u'(.*?)',")

        self.h_margin = 100;
        self.v_margin = 100;
        
        self.n_attempts = 1
        self.n_h_regions = 4
        self.n_v_regions = 3
    
        cv2.namedWindow("image", cv2.WINDOW_NORMAL)
	    
        self.auth = cloudsight.OAuth('t-xw3Mn06dkObZwsi8qpcA', 'laJ83zYRxAVpls1Aera8Mg')
        self.api = cloudsight.API(self.auth)
        
        self.image_regions = None
Exemple #2
0
def Caption(image_name, passs):
    auth = CV.SimpleAuth(passs)
    conn = CV.API(auth)
    Filter_chocolate = ['chocolate', 'pizza']
    filter_phone = [
        'smartphone', 'phone', 'mobile', 'Smartphone', 'Phone', 'Mobile'
    ]
    with open(image_name, 'rb') as f:
        response = conn.image_request(f, image_name, {
            'image_request[locale]': 'en-US',
        })
    status = conn.wait(response['token'], timeout=30)
    status = conn.image_response(response['token'])
    if status['status'] != cloudsight.STATUS_NOT_COMPLETED:
        try:
            caption = status['name']
            for content in Filter_chocolate:
                if content in caption:
                    print("Warning: Eating %s is injurious to Health.." %
                          content)
                    GV.speak(
                        'Warning: Eating Cholocate is injurious to Health.... Image Content'
                    )
                    break
            for content in filter_phone:
                if content in caption:
                    caption = "Alert: %s Detected.. Filtered Content.." % content

            GV.speak(caption)
            return (caption)
        except:
            print('Cannot Process this image')
    else:
        print('Cannot Process Image')
Exemple #3
0
    def testGetCompletedResponse(self):
        auth = cloudsight.SimpleAuth('test-token')
        api = cloudsight.API(auth)

        response = api.image_response('BjMGgyIZQt7QNPNZKmzq2A')

        assert response['status'] == 'completed'
        assert response['token']  == 'BjMGgyIZQt7QNPNZKmzq2A'
        assert response['name']   == 'Apple logo'
Exemple #4
0
    def testSendRequest(self):
        auth = cloudsight.SimpleAuth('test-token')
        api = cloudsight.API(auth)
        response = api.remote_image_request('https://storage.googleapis.com/iex/api/logos/AAPL.png', {
            'image_request[locale]': 'en-US',
        })

        assert response['status'] == 'not completed'
        assert response['token']  == 'BjMGgyIZQt7QNPNZKmzq2A'
    def __init__(self):
        rospy.Subscriber('/camera/rgb/image_raw/crop', String,
                         self.CropImageFileCallback)

        self.pubGoal = rospy.Publisher('/hearts/or/item', String, queue_size=1)
        self.pubStatus = rospy.Publisher('/hearts/cloudsight/status',
                                         String,
                                         queue_size=1)

        self.auth = cloudsight.OAuth('t-xw3Mn06dkObZwsi8qpcA',
                                     'laJ83zYRxAVpls1Aera8Mg')
        self.api = cloudsight.API(self.auth)

        self.image_attempts = 0
        self.max_attempts = 2
def call_vision_api(image_filename, api_keys):
    api_key = api_keys['cloudsight']['api_key']

    # Via example found here:
    # https://github.com/cloudsight/cloudsight-python

    auth = cloudsight.SimpleAuth(api_key)
    api = cloudsight.API(auth)

    with open(image_filename, 'rb') as image_file:
        response = api.image_request(image_file, image_filename)

    response = api.wait(response['token'], timeout=60)

    return response
def Caption(image_name, passs):
    auth = CS.SimpleAuth(passs)
    conn = CS.API(auth)
    Filter_chocolate = ['chocolate', 'pizza']
    filter_phone = [
        'smartphone', 'phone', 'mobile', 'Smartphone', 'Phone', 'Mobile'
    ]
    filter_cigarette = ['cigarette', 'cigarettes', 'smoking', 'smoke']
    with open(image_name, 'rb') as f:
        response = conn.image_request(f, image_name, {
            'image_request[locale]': 'en-US',
        })
    status = conn.wait(response['token'], timeout=30)
    status = conn.image_response(response['token'])
    if status['status'] != CS.STATUS_NOT_COMPLETED:
        try:
            caption = status['name']
            for content in Filter_chocolate:
                if content in caption:
                    message = "Warning: Eating %s is injurious to Health...Image Content" % content
                    #GV.speak('Warning: Eating Cholocate is injurious to Health.... Image Content\n')
                    message = message + caption
                    caption = message
                    break
            for content in filter_cigarette:
                if content in caption:
                    message = "Warning: Smoking %s is injurious to Health...Image Content. " % content
                    #GV.speak('Warning: Smoking %s is injurious to Health.... Image Content. \n' %content)
                    message = message + caption
                    caption = message
                    break
            for content in filter_phone:
                if content in caption:
                    caption = "Alert: %s Detected.. Filtered Content.." % content

            person = DT.Recognise_Face(image_name)
            if person != 0:
                message = 'You are looking at %s. ' % person
                message = message + caption
                caption = message
            GV.speak(caption)
            return (caption)
        except:
            print('Cannot Process this image')
    else:
        print('Cannot Process Image')
 def fetch_labels(self, image_data, image_extension):
     try:
         auth = cloudsight.SimpleAuth(self._api_key)
         api = cloudsight.API(auth)
         response = api.image_request(image_data,
                                      'image.{}'.format(image_extension),
                                      {'image_request[locale]': 'en-US'})
         api.wait(response['token'], timeout=30)
         response = api.image_response(response['token'])
         status = response['status']
         if status == cloudsight.STATUS_COMPLETED:
             return [ImageLabel(label=response['name'], rank=1)]
         elif status == cloudsight.STATUS_SKIPPED:
             raise ImageRecognitionException(response['reason'])
         else:
             raise ImageRecognitionException('Service unavailable')
     except APIError:
         raise ImageRecognitionException('Service unavailable')
Exemple #9
0
 def post(self, request):
     # add a new image into database
     if request.POST.get("image"):
         image_feedback = request.POST.get("image")
         format, imgstr = image_feedback.split(';base64,')
         ext = format.split('/')[-1]
         data = ContentFile(base64.b64decode(imgstr), name='temp.' + ext)
         auth = cloudsight.SimpleAuth('1bRy8uWYdSP9iErp-lImYg')
         api = cloudsight.API(auth)
         response = api.image_request(data, 'temp.' + ext, {
             'image_request[locale]': 'en-US',
         })
         print "wait"
         status = api.wait(response['token'], timeout=30)
         print "get image response"
         status = api.image_response(response['token'])
         if status['status'] != cloudsight.STATUS_NOT_COMPLETED:
             # Done!
             print "inside completed"
             print status
             category = status['name']
             score_dict = general_operations._get_priority_score_dict(
                 category, datetime.datetime.now())
             priority = general_operations._get_priority_score(score_dict)
             image = ImageFeedback(image=data,
                                   category=category,
                                   date_created=timezone.now(),
                                   priority=priority)
             image.save()
             # category = general_operations.get_image_classification(data)
             # image_name = category
             # score_dict = general_operations._get_priority_score_dict(category, datetime.datetime.now())
             # priority = general_operations._get_priority_score(score_dict)
             # image = ImageFeedback(image=data, category=category, date_created=timezone.now(), priority=priority)
             # image.save()
             return JsonResponse({"success": True}, status=200)
         print "end"
         print "error with api"
         return HttpResponse(status=404)
     print "error with image form"
     return HttpResponse(status=404)
Exemple #10
0
 def post(self, request):
     img = request.FILES.get('img')
     if img is None:
         return HttpResponse('You need upload a picture!')
     auth = cloudsight.SimpleAuth('bbzL7Oh6D2L1krnQZ5OfKg')
     api = cloudsight.API(auth)
     InputFile = img.name
     print(InputFile)
     response = api.image_request(img, InputFile, {
         'image_request[locale]': 'zh-CN',
         'image_request[language]': 'zh-CN'
     })
     print(response)
     status = api.wait(response['token'], timeout=30)
     data = {
         'name': status['name'],
         'url': status['url'],
         'code': 200,
     }
     return HttpResponse(json.dumps(data),
                         content_type='application/json;charset=utf-8')
Exemple #11
0
def take_picture():
    camera = camera_factory()

    snap = camera.snapshot()
    print "Picture Taken"
    path = "img/snap%d.jpg" % time.time()
    with open(path, "w") as outfile:
        outfile.write(snap)

    auth = cloudsight.SimpleAuth('0XG_2yQHzZgMHyjVVVskNQ')
    api = cloudsight.API(auth)
    with open(path, 'rb') as f:
        response = api.image_request(f, path, {
            'image_request[locale]': 'en-US',
        })
    status = api.wait(response['token'], timeout=30)
    name = str(status["name"])
    print name
    engine = pyttsx.init()
    engine.setProperty('rate', 140)
    engine.say(name)
    engine.runAndWait()
Exemple #12
0
def main() :

    # Make API call for authentication with API key
    auth = cloudsight.SimpleAuth('OMITTED')

    api = cloudsight.API(auth)

    # Iterate through the number of images the user would like described
    for x in range(numImages):
        string = str(x)
        # Files must be called from 0.jpg onwards so it knows how many to iterate
        file = string + '.jpg'
        # If the file doesn't exist, inform the user and exit the for loop
        if os.path.exists(file) == False:
            print("The file " + file + " does not exist. Please check the filenames are correctly formatted. \n")
            print("Now exiting the loop. Please rerun the program. \n")
            break
        # Open the image and downsize the file so it is easier and faster to upload
        im = Image.open(file)
        im.thumbnail((600, 600))
        # Save the smaller image so we can upload to the API
        im.save(string + 'cloudsight.jpg')
        # Open the image and make the request to the API
        with open(string + 'cloudsight.jpg', 'rb') as f:
            response = api.image_request(f, string + 'cloudsight.jpg', {'image_request[locale]': 'en-US', })
            # Maximum waiting time of 30 seconds - just in case
            status = api.wait(response['token'], timeout=30)

        # Print out the caption returned
        output = status['name']
        print(output)
        print("Preparing text to speech. \n")
        # Call the text to speech function with caption as parameter
        textSpeech("The image can be described as " + output)
        # Wait so the text to speech can finish before starting to say the joke
        wait()
        # Call the joke function with the caption as a parameter
        dadJoke(output)
Exemple #13
0
 def post(self, request):
     img = request.FILES.get('picture')
     if img is None:
         return HttpResponse('You need upload a picture!')
     auth = cloudsight.SimpleAuth('wslbEXDJIZNwAWW3BOP0g')
     api = cloudsight.API(auth)
     InputFile = img.name
     response = api.image_request(img, InputFile, {
         'image_request[locale]': 'zh-CN',
         'image_request[language]': 'zh-CN'
     })
     status = api.wait(response['token'], timeout=30)
     userImg = UserImg(
         name=status['name'],
         url=status['url'],
     )
     data = {
         'name': status['name'],
         'url': status['url'],
         'code': 200,
     }
     userImg.save()
     return HttpResponse(json.dumps(data),
                         content_type="application/json;charset=utf-8")
Exemple #14
0
import cloudsight
from flask import Flask
import os
import sys

# INIT
#api_key = "q1RmugXxnjuAa_4mBSW93w"
#secret = "M8z18rMeiyenNIntIevW1Q"
api_key = "8ZyGYkpmEVK1wJDb5uiBog"
secret = "tx25bk7L_J-DqLPCkDBrOg"
#auth = cloudsight.SimpleAuth(api_key)
auth = cloudsight.OAuth(api_key, secret)
api = cloudsight.API(auth)

with open('test_image.jpg', 'rb') as f:
    response = api.image_request(f, 'your-file.jpg', {
        'image_request[locale]': 'en-US',
    })

status = api.wait(response['token'], timeout=30)


Exemple #15
0
    def testNewApi(self):
        auth = cloudsight.SimpleAuth('your-api-key')
        api = cloudsight.API(auth)

        assert api.auth == auth
Exemple #16
0
def auth():
    auth = cloudsight.OAuth('ID', 'Key')
    api = cloudsight.API(auth)
    return api