-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_analyse.py
More file actions
73 lines (65 loc) · 2.65 KB
/
capture_analyse.py
File metadata and controls
73 lines (65 loc) · 2.65 KB
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
import sys
import cv2
from computer_vision_gpt_approach.computer_vision import \
resize_and_encode_image, match_image_to_artwork
# Dictionary mapping long exhibit names to sets of vision tags
ARTWORKS = {
"The Scream by Edvard Munch": {
"the scream", "edvard munch", "screaming figure", "hands on face",
"swirling sky", "expressionist style", "vivid colours", "psychological expression"
},
"Starry Night by Vincent van Gogh": {
"starry-night", "van-gogh", "swirling-sky", "yellow-stars", "blue-sky",
"cypress-tree", "village-at-night", "expressionist-art", "moon",
"blue-and-yellow-painting", "famous-artwork", "post-impressionism"
},
"Sunflowers by Vincent van Gogh": {
"sunflowers", "vase with flowers", "yellow petals", "wilted petals",
"green stems", "warm ochre background", "post-impressionist style",
"Van Gogh signature", "textured impasto brushwork"
},
"Liberty Leading the People by Eugène Delacroix": {
"romanticism", "oil painting", "historical painting", "Eugène Delacroix",
"revolutionary scene", "French flag", "bare-breasted woman", "tricolour flag",
"heroic symbolism"
},
"Mona Lisa by Leonardo da Vinci": {
"portrait", "woman", "smile", "Leonardo da Vinci", "Renaissance",
"sfumato", "folded hands", "calm expression"
},
"Ancient Egyptian Statue": {
"metal-figurine", "brass-statue", "decorative-figure", "ethnic-art",
"tribal-sculpture", "african-style-decor", "woman-holding-bowl",
"red-and-black-dress", "ornamental-design", "engraved-base",
"painted-metal-statue", "folk-art-sculpture", "bronze-body-figure"
},
"Plushy Dog Sculpture": {
"plush_dog", "brown_dog", "toy_dog", "fabric_dog", "stuffed_animal",
"dog_doorstop", "bead_eyes", "bow_collar", "floppy_ears", "round_body"
}
}
def cap_anal() -> str:
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("[ERROR] Cannot access webcam")
sys.exit(1)
ret, frame = cap.read()
if not ret:
print("[ERROR] Failed to capture frame")
sys.exit(1)
filename = "frame.jpg"
cv2.imwrite(filename, frame)
print("[INFO] Frame captured. Analyzing...")
try:
encoded = resize_and_encode_image(filename)
match = match_image_to_artwork(encoded, ARTWORKS)
print(f"[RESULT] Matched artwork: {match}")
cap.release()
cv2.destroyAllWindows()
return match
except Exception as e:
print(f"[ERROR] {e}")
sys.exit(1)
# If run directly, execute a test capture
if __name__ == "__main__":
cap_anal()