-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_export.py
More file actions
37 lines (33 loc) · 1.3 KB
/
Copy pathcsv_export.py
File metadata and controls
37 lines (33 loc) · 1.3 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
# csv_export.py
import csv
import os
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def save_features_to_csv(image_id, features, bbox, label, csv_file):
"""
Save the extracted features into a CSV file.
The CSV header is: Image_ID, Sharpness, Edge_Density, SIFT_Keypoint_Count,
Object_Count, Tampered_Ratio, Forgery_BBox, Label.
"""
header = ["Image_ID", "Sharpness", "Edge_Density", "SIFT_Keypoint_Count",
"Object_Count", "Tampered_Ratio", "Forgery_BBox", "Label"]
file_exists = os.path.exists(csv_file)
try:
with open(csv_file, mode="a", newline="") as file:
writer = csv.writer(file)
if not file_exists:
writer.writerow(header)
writer.writerow([
image_id,
features.get('sharpness', 0),
features.get('edge_density', 0),
features.get('sift_count', 0),
features.get('object_count', 0),
features.get('tampered_ratio', 0),
str(bbox), # Save bbox as string
label
])
logger.info("Saved features for %s", image_id)
except Exception as e:
logger.error("Error writing to CSV: %s", e)