import argparse import csv import sys import os from .dfake_func import gen_feats, read_bboxes def process_dct(input_image, bbox_path, output_path=None, msig_coeffs=32, resize=256): """ Process an image with DCT features Args: input_image: Path to the input image bbox_path: Path to the CSV file with bounding boxes output_path: Path to save the output CSV msig_coeffs: Number of DCT coefficients resize: Size to resize image before DCT calculation Returns: The path to the output CSV file """ # Default output path if not provided if not output_path: output_dir = os.path.dirname(input_image) base_name = os.path.basename(input_image).rsplit('.', 1)[0] output_path = os.path.join(output_dir, f"{base_name}_dct_features.csv") print(f"Processing DCT features for {input_image}") print(f"Using bounding boxes from {bbox_path}") print(f"Output will be saved to {output_path}") try: # Read bounding boxes bounding_boxes = read_bboxes(bbox_path) # Generate features gen_feats( input_image=input_image, bounding_boxes=bounding_boxes, output_csv=output_path, msig_coeffs=msig_coeffs, resize_dct=resize ) print(f"DCT features successfully saved to {output_path}") return output_path except Exception as e: print(f"Error in DCT processing: {str(e)}") raise e def main(): parser = argparse.ArgumentParser(description='Generate DCT features from image') parser.add_argument('-i', '--image', required=True, help='Input image path') parser.add_argument('-b', '--bboxes', required=True, help='Bounding boxes CSV file') parser.add_argument('-o', '--output', help='Output CSV path') parser.add_argument('-m', '--msig', type=int, default=32, help='Number of DCT coefficients') parser.add_argument('-r', '--resize', type=int, default=256, help='Resize dimension for DCT') args = parser.parse_args() process_dct( args.image, args.bboxes, args.output, args.msig, args.resize ) if __name__ == "__main__": main()