File size: 5,440 Bytes
4c30c49
 
775e795
 
83aa815
775e795
 
 
 
 
 
 
83aa815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c30c49
83aa815
 
4c30c49
 
83aa815
4c30c49
 
83aa815
4c30c49
 
83aa815
 
 
775e795
 
4c30c49
 
775e795
83aa815
 
 
 
4c30c49
 
83aa815
 
 
 
 
 
 
 
 
 
4c30c49
83aa815
 
4c30c49
83aa815
4c30c49
83aa815
775e795
 
4c30c49
83aa815
775e795
4c30c49
83aa815
 
 
 
 
 
 
 
 
4c30c49
83aa815
 
4c30c49
83aa815
4c30c49
83aa815
775e795
 
4c30c49
 
775e795
83aa815
 
 
 
4c30c49
83aa815
 
 
 
 
 
 
 
 
 
 
 
 
4c30c49
 
83aa815
 
775e795
 
fb8e68c
 
83aa815
 
 
 
 
 
 
 
 
f45898a
 
83aa815
 
fb8e68c
83aa815
fb8e68c
83aa815
 
4c30c49
83aa815
f45898a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import requests

index_counter = 0  # Global counter for video indexes

def videoAnalysis(sas_token, sas_url, search):
    
    global index_counter  # Access the global counter variable

    index_counter += 1
    index_name = f"video-index-{index_counter}"

    url = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}?api-version=2023-05-01-preview"
    headers = {
        "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
        "Content-Type": "application/json"
    }

    data = {
        "metadataSchema": {
            "fields": [
                {
                    "name": "cameraId",
                    "searchable": False,
                    "filterable": True,
                    "type": "string"
                },
                {
                    "name": "timestamp",
                    "searchable": False,
                    "filterable": True,
                    "type": "datetime"
                }
            ]
        },
        "features": [
            {
                "name": "vision",
                "domain": "surveillance"
            },
            {
                "name": "speech"
            }
        ]
    }


    response = requests.put(url, json=data, headers=headers)
    
    #test code for errors
    print("Response Status Code:", response.status_code)
    print("Response Content:", response.text)


    url_index = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}/ingestions/my-ingestion?api-version=2023-05-01-preview"
    headers = {
        "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
        "Content-Type": "application/json"
    }


    data_index = {
        "videos": [
            {
                "mode": "add",
                "documentId": sas_token,
                "documentUrl": sas_url,
                "metadata": {
                    "cameraId": "camera1",
                    "timestamp": "2024-02-09 00:02:14"
                }
            }
        ]
    }

    response_index = requests.put(url_index, json=data_index, headers=headers)

    #test code for errors
    print("Index Ingestion - Response Status Code:", response_index.status_code)
    print("Index Ingestion - Response Content:", response_index.text)

    # Assuming you want to ingest another video with a different ingestion name
    url_new_ingestion = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}/ingestions/new-ingestion?api-version=2023-05-01-preview"

    data_new_ingestion = {
        "videos": [
            {
                "mode": "add",
                "documentId": "new_document_id",
                "documentUrl": "https://example.blob.core.windows.net/videos/new_video.mp4?sas_token_here",
                "metadata": {
                    "cameraId": "camera3"
                }
            }
        ]
    }

    response_new_ingestion = requests.put(url_new_ingestion, json=data_new_ingestion, headers=headers)

    #used to test code for errors
    print("New Ingestion - Response Status Code:", response_new_ingestion.status_code)
    print("New Ingestion - Response Content:", response_new_ingestion.text)


    url_query = f"https://explosion.cognitiveservices.azure.com/computervision/retrieval/indexes/{index_name}:queryByText?api-version=2023-05-01-preview"
    headers = {
        "Ocp-Apim-Subscription-Key": "c54eec632ae5413e8075e3f825727822",
        "Content-Type": "application/json"
    }

    data_query = {
        "queryText": search,
        "filters": {
            "stringFilters": [
                {
                    "fieldName": "cameraId",
                    "values": [
                        "camera1"
                    ]
                }
            ],
            "featureFilters": ["vision"]
        }
    }

    response_query = requests.post(url_query, json=data_query, headers=headers)

    if response_query.text == """{"error":{"code":"InvalidRequest","message":"Value for indexName is invalid."}}""":
        videoAnalysis(sas_token,sas_url, search)    
    else: 
        return response_query.text

#Enter the sas token
sas_token_1 = "sp=r&st=2024-02-09T12:33:24Z&se=2025-08-06T20:33:24Z&spr=https&sv=2022-11-02&sr=b&sig=V%2Fq56JjGcL60r0vt3oAPjzx%2FZMu5%2BJo%2BfjKkJF2ccgo%3D"
#the sas url
sas_url_1= "https://store1video.blob.core.windows.net/haptic-vid/test_video.mp4?sp=r&st=2024-02-09T12:33:24Z&se=2025-08-06T20:33:24Z&spr=https&sv=2022-11-02&sr=b&sig=V%2Fq56JjGcL60r0vt3oAPjzx%2FZMu5%2BJo%2BfjKkJF2ccgo%3D"
#query of what you are looking for 
instance_1 = "Explosion"

#calling the method returns the nested list of the time frames
#test_explosion = videoAnalysis(sas_token_1, sas_url_1, instance_1)
#print(test_explosion)

#Enter the sas token
sas_token_2 = "sp=r&st=2024-03-18T09:48:32Z&se=2026-07-02T17:48:32Z&spr=https&sv=2022-11-02&sr=b&sig=hLiFrDUtrutW9FWWRR7Z0Kbc4wkHs28YR9RXjVxw8uc%3D"
#the sas url
sas_url_2= "https://store1video.blob.core.windows.net/haptic-vid/desert_vehicle_test.mp4?sp=r&st=2024-03-18T09:48:32Z&se=2026-07-02T17:48:32Z&spr=https&sv=2022-11-02&sr=b&sig=hLiFrDUtrutW9FWWRR7Z0Kbc4wkHs28YR9RXjVxw8uc%3D"
#query of what you are looking for 
instance_2 = "Vehicle racing" 

#calling the method returns the nested list of the time frames
#test_vehicle = videoAnalysis(sas_token_2, sas_url_2, instance_2)
#print(test_vehicle)