nesian42ryukaiel / videoframepy

First Web + Python project.
MIT License
0 stars 0 forks source link

videoframepy does not provide any features #6

Open wholesomemoon opened 3 years ago

wholesomemoon commented 3 years ago

The current videoframepy is as follows:


# -------------------------------------------------------------------- #
# client.py is imported from:
# https://gist.github.com/edumucelli/c2843ed1f6e13ed4706d63be87a0d671
# -------------------------------------------------------------------- #

import requests  # "a simple, yet elegant HTTP library"
import json      # supported by Python
import cv2

addr = 'http://localhost:5000'
test_url = addr + '/api/test'

# prepare headers for http request
content_type = 'image/jpeg'
headers = {'content-type': content_type}

img = cv2.imread('webgi.jpg')

# encode image as jpeg
_, img_encoded = cv2.imencode('.jpg', img)

# send http request with image and receive response
response = requests.post(test_url, data=img_encoded.tostring(), headers=headers)
# decode response
print(response.text)

# expected output: {u'message': u'image received. size=124x124'}

The thing is that the videoframepy cannot be never used by an external user in this form. A reasonable solution is to wrap all the main logics in the form of a function and provide the function to the external users, as in the form of an API.

wholesomemoon commented 3 years ago

Also, it is not good to disclose the IP address. It is necessary to think about how to hide the address from the public.

wholesomemoon commented 3 years ago

Maybe it will be good idea to pass a geojson file into API. For instance,


class VideoFramePyMeta(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            instance = super().__call__(*args, **kwargs)
            cls._instances[cls] = instance
        return cls._instances[cls]

class VideoFramePy(metaclass=VideoFramePyMeta):
    def run(self, json):
        # TODO: complete your logic 

It would be reasonable to insert parameters such as an image path, encoding type, or server URL into the geojson file. This is because external users can set the parameters up. BTW, the API is designed to use singleton in this case. Maybe sample codes will be formed like:


import videoframepy

if __name__ == "__main__":
    vfpy = VideoFramePy()
    vfpy.run('app.json')
nesian42ryukaiel commented 2 years ago

My next step will be making the server running code pick up the sent images, and do something with it. At the very least, it will extract the average RGB value of an image and send it together with the initial response message. I should modularize each function, right?

wholesomemoon commented 2 years ago

You said that you would modularize each function, but actually, I don't know if modularization would be meaningful if you only aim to get the RGB average. Because if you're going to get the average RGB value anyway, it'll be over in 2-3 lines of code at most of the time.

wholesomemoon commented 2 years ago

In other words, the length of your logic is too short(small) to divide into such modules.