Spaces:
Sleeping
Sleeping
Update database.py
Browse files- database.py +16 -18
database.py
CHANGED
|
@@ -387,41 +387,39 @@ class DogDatabase:
|
|
| 387 |
print(f"Error adding dog image: {e}")
|
| 388 |
raise
|
| 389 |
|
| 390 |
-
def get_dog_images(self, dog_id, validated_only
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
conn.row_factory = sqlite3.Row
|
| 394 |
-
cursor = conn.cursor()
|
| 395 |
-
|
| 396 |
query = "SELECT * FROM dog_images WHERE dog_id = ?"
|
| 397 |
params = [dog_id]
|
| 398 |
-
|
| 399 |
if validated_only:
|
| 400 |
query += " AND is_validated = 1"
|
| 401 |
if not include_discarded:
|
| 402 |
query += " AND is_discarded = 0"
|
|
|
|
| 403 |
|
| 404 |
-
cursor.execute(query, params)
|
| 405 |
-
rows = cursor.fetchall()
|
| 406 |
|
| 407 |
images = []
|
| 408 |
for row in rows:
|
| 409 |
-
|
| 410 |
-
|
|
|
|
|
|
|
| 411 |
|
| 412 |
images.append({
|
| 413 |
'image_id': row['image_id'],
|
| 414 |
'image': image,
|
| 415 |
-
'
|
| 416 |
-
'
|
| 417 |
'confidence': row['confidence'],
|
| 418 |
-
'
|
| 419 |
-
'video_source': row['video_source'],
|
| 420 |
'is_validated': row['is_validated'],
|
| 421 |
-
'is_discarded': row['is_discarded']
|
|
|
|
| 422 |
})
|
| 423 |
-
|
| 424 |
-
conn.close()
|
| 425 |
return images
|
| 426 |
|
| 427 |
def validate_image(self, image_id: int, is_valid: bool = True):
|
|
|
|
| 387 |
print(f"Error adding dog image: {e}")
|
| 388 |
raise
|
| 389 |
|
| 390 |
+
def get_dog_images(self, dog_id: int, validated_only: bool = False,
|
| 391 |
+
include_discarded: bool = False) -> List[Dict]:
|
| 392 |
+
"""Get all images for a dog"""
|
|
|
|
|
|
|
|
|
|
| 393 |
query = "SELECT * FROM dog_images WHERE dog_id = ?"
|
| 394 |
params = [dog_id]
|
|
|
|
| 395 |
if validated_only:
|
| 396 |
query += " AND is_validated = 1"
|
| 397 |
if not include_discarded:
|
| 398 |
query += " AND is_discarded = 0"
|
| 399 |
+
query += " ORDER BY timestamp DESC"
|
| 400 |
|
| 401 |
+
self.cursor.execute(query, params)
|
| 402 |
+
rows = self.cursor.fetchall()
|
| 403 |
|
| 404 |
images = []
|
| 405 |
for row in rows:
|
| 406 |
+
# ✅ Decode base64 string to bytes first
|
| 407 |
+
image_bytes = base64.b64decode(row['image_data'])
|
| 408 |
+
nparr = np.frombuffer(image_bytes, np.uint8)
|
| 409 |
+
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
| 410 |
|
| 411 |
images.append({
|
| 412 |
'image_id': row['image_id'],
|
| 413 |
'image': image,
|
| 414 |
+
'thumbnail': row['thumbnail'],
|
| 415 |
+
'bbox': json.loads(row['bbox']) if row['bbox'] else [],
|
| 416 |
'confidence': row['confidence'],
|
| 417 |
+
'frame_number': row['frame_number'] if 'frame_number' in row.keys() else None,
|
| 418 |
+
'video_source': row['video_source'] if 'video_source' in row.keys() else None,
|
| 419 |
'is_validated': row['is_validated'],
|
| 420 |
+
'is_discarded': row['is_discarded'],
|
| 421 |
+
'pose_keypoints': json.loads(row['pose_keypoints']) if row.get('pose_keypoints') else None
|
| 422 |
})
|
|
|
|
|
|
|
| 423 |
return images
|
| 424 |
|
| 425 |
def validate_image(self, image_id: int, is_valid: bool = True):
|