Exemplo n.º 1
0
def test_detection_file():

    detection = Detection(config)

    res = detection.detectObject(os.path.join(IMAGES_DIR, "detection.jpg"))

    assert len(res) == 3
Exemplo n.º 2
0
def test_detection_file():

    detection = Detection(config, name="mask")

    res = detection.detectObject(os.path.join(IMAGES_DIR, "pelosi.webp"))

    assert len(res) == 1
Exemplo n.º 3
0
def test_detection_url():

    detection = Detection(config)

    res = detection.detectObject(
        "https://docs.deepstack.cc/_images/family-and-dog.jpg")

    assert len(res) == 3
Exemplo n.º 4
0
def test_detection_pil():

    detection = Detection(config, name="mask")

    img = Image.open(os.path.join(IMAGES_DIR, "pelosi.webp"))

    res = detection.detectObject(img)

    assert len(res) == 1
Exemplo n.º 5
0
def test_detection_cv2():

    detection = Detection(config, name="mask")

    img = cv2.imread(os.path.join(IMAGES_DIR, "pelosi.webp"))

    res = detection.detectObject(img)

    assert len(res) == 1
Exemplo n.º 6
0
def test_detection_pil():

    detection = Detection(config)

    img = Image.open(os.path.join(IMAGES_DIR, "detection.jpg"))

    res = detection.detectObject(img)

    assert len(res) == 3
Exemplo n.º 7
0
def test_detection_cv2():

    detection = Detection(config)

    img = cv2.imread(os.path.join(IMAGES_DIR, "detection.jpg"))

    res = detection.detectObject(img)

    assert len(res) == 3
Exemplo n.º 8
0
def test_detection_bytes():

    detection = Detection(config)

    img = Image.open(os.path.join(IMAGES_DIR, "detection.jpg"))

    img_data = pilToBytes(img)

    res = detection.detectObject(img_data)

    assert len(res) == 3
Exemplo n.º 9
0
def test_detection_video():

    detection = Detection(config, name="mask")

    video = os.path.join(IMAGES_DIR, "video.mp4")

    res = detection.detectObjectVideo(video, output="vid.mp4")

    savedVid = cv2.VideoCapture("vid.mp4")

    totalframecount = int(savedVid.get(cv2.CAP_PROP_FRAME_COUNT))

    assert totalframecount == 1193
Exemplo n.º 10
0
from deepstack_sdk import Detection, ServerConfig
import os

config = ServerConfig("http://localhost:80")
detector = Detection(config=config, name="dark")

detections = detector.detectObject(image=os.path.join("images", "image.jpg"),
                                   output=os.path.join("images",
                                                       "image_detected.jpg"))

for detection in detections:
    print("Name: {}".format(detection.label))
    print("Confidence: {}".format(detection.confidence))
    print("x_min: {}".format(detection.x_min))
    print("x_max: {}".format(detection.x_max))
    print("y_min: {}".format(detection.y_min))
    print("y_max: {}".format(detection.y_max))
    print("-----------------------")
Exemplo n.º 11
0
from deepstack_sdk import ServerConfig, Detection

config = ServerConfig("http://localhost:80")
detection = Detection(config)

detection.detectObjectVideo("video.mp4",output="video_output.mp4")


"""
:: detection.detectObjectVideo()

--- Available Paramaters

- video (file, Camera video feed IP, integer for OpenCV Camera e.g 0, 1, 2)
- min_confidence (0.1 to 1.0)
- codec (Default: cv2.VideoWriter_fourcc(*'mp4v') )
- fps (frames per second)
- continue_on_error (Default: false)
- output (file path, cv2.VideoWriter)
- output_font (cv2 font)
- output_font_color ( r, g, b )
"""
Exemplo n.º 12
0
from deepstack_sdk import ServerConfig, Detection
import cv2

config = ServerConfig("http://localhost:80")
detection = Detection(config)

cv2_image = cv2.imread("image.jpg")
response = detection.detectObject(cv2_image, output="image_output.jpg")

for obj in response:
    print(
        "Name: {}, Confidence: {}, x_min: {}, y_min: {}, x_max: {}, y_max: {}".
        format(obj.label, obj.confidence, obj.x_min, obj.y_min, obj.x_max,
               obj.y_max))
from deepstack_sdk import ServerConfig, Detection

config = ServerConfig("http://localhost:80")
detection = Detection(config, name="openlogo")

response = detection.detectObject("image.jpg",output="image_output.jpg")

for obj in response:
    print("Name: {}, Confidence: {}, x_min: {}, y_min: {}, x_max: {}, y_max: {}".format(obj.label, obj.confidence, obj.x_min, obj.y_min, obj.x_max, obj.y_max))

"""
:: detection.detectObject()

--- Available Paramaters

- image (file, numpy array, PIL Image, image bytes, url)
- format (jpg, png)
- min_confidence (0.1 to 1.0)
- callback (function name, parses in image_byte [without label and boxes] and detections into the function)
- output (file path of none if you don't want to save to file)
- output_font (cv2 font)
- output_font_color ( r, g, b )
"""
from deepstack_sdk import ServerConfig, Detection


def detection_callback(input_image_byte, detection_result):
    # Get detected image byte and save
    with open("detected_image.jpg", "wb") as writer:
        writer.write(input_image_byte)
    
    # Process detection result
    for obj in detection_result:
        print("Name: {}, Confidence: {}, x_min: {}, y_min: {}, x_max: {}, y_max: {}".format(obj.label, obj.confidence, obj.x_min, obj.y_min, obj.x_max, obj.y_max))

    # You can do other stuffs with the image and the detection results in this function
    

config = ServerConfig("http://localhost:80")
detection = Detection(config)

image_byte = open("image.jpg", "rb").read()
response = detection.detectObject(image_byte, callback=detection_callback)
Exemplo n.º 15
0
from deepstack_sdk import ServerConfig, Detection

config = ServerConfig("http://localhost:89")
detection = Detection(config)

response = detection.detectObject("detection.jpg", output="output_image.jpg")

for obj in response:
    print("Name: {}, Confidence: {}".format(obj.label, obj.confidence))