start
This commit is contained in:
@@ -354,6 +354,8 @@ public class TroostwijkScraper {
|
||||
* discovers Dutch auctions, scrapes lots, and begins monitoring.
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("=== Troostwijk Auction Scraper ===\n");
|
||||
|
||||
// Configuration parameters (replace with your own values)
|
||||
String databaseFile = "troostwijk.db";
|
||||
|
||||
@@ -366,27 +368,34 @@ public class TroostwijkScraper {
|
||||
// Example: "smtp:your.email@gmail.com:abcd1234efgh5678:recipient@example.com"
|
||||
// Get app password: Google Account > Security > 2-Step Verification > App passwords
|
||||
|
||||
String yoloCfg = "models/yolov4.cfg"; // path to YOLO config file
|
||||
String yoloWeights = "models/yolov4.weights"; // path to YOLO weights file
|
||||
String yoloClasses = "models/coco.names"; // list of class names
|
||||
// YOLO model paths (optional - scraper works without object detection)
|
||||
String yoloCfg = "models/yolov4.cfg";
|
||||
String yoloWeights = "models/yolov4.weights";
|
||||
String yoloClasses = "models/coco.names";
|
||||
|
||||
// Load native OpenCV library
|
||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||
|
||||
System.out.println("Initializing scraper...");
|
||||
TroostwijkScraper scraper = new TroostwijkScraper(databaseFile, notificationConfig, "",
|
||||
yoloCfg, yoloWeights, yoloClasses);
|
||||
|
||||
// Step 1: Discover auctions in NL
|
||||
System.out.println("\n[1/3] Discovering Dutch auctions...");
|
||||
List<Integer> auctions = scraper.discoverDutchAuctions();
|
||||
System.out.println("Found auctions: " + auctions);
|
||||
System.out.println("✓ Found " + auctions.size() + " auctions: " + auctions);
|
||||
|
||||
// Step 2: Fetch lots for each auction
|
||||
System.out.println("\n[2/3] Fetching lot details...");
|
||||
for (int saleId : auctions) {
|
||||
System.out.println(" Processing sale " + saleId + "...");
|
||||
scraper.fetchLotsForSale(saleId);
|
||||
}
|
||||
|
||||
// Step 3: Start monitoring bids and closures
|
||||
System.out.println("\n[3/3] Starting monitoring service...");
|
||||
scraper.scheduleMonitoring();
|
||||
System.out.println("✓ Monitoring active. Press Ctrl+C to stop.\n");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -710,23 +719,53 @@ public class TroostwijkScraper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Service for performing object detection on images using OpenCV’s DNN
|
||||
* Service for performing object detection on images using OpenCV's DNN
|
||||
* module. The DNN module can load pre‑trained models from several
|
||||
* frameworks (Darknet, TensorFlow, ONNX, etc.)【784097309529506†L209-L233】. Here
|
||||
* we load a YOLO model (Darknet) by specifying the configuration and
|
||||
* weights files. For each image we run a forward pass and return a
|
||||
* list of detected class labels.
|
||||
*
|
||||
* If model files are not found, the service operates in disabled mode
|
||||
* and returns empty lists.
|
||||
*/
|
||||
static class ObjectDetectionService {
|
||||
private final Net net;
|
||||
private final List<String> classNames;
|
||||
private final boolean enabled;
|
||||
|
||||
ObjectDetectionService(String cfgPath, String weightsPath, String classNamesPath) throws IOException {
|
||||
// Load network
|
||||
this.net = Dnn.readNetFromDarknet(cfgPath, weightsPath);
|
||||
this.net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
this.net.setPreferableTarget(DNN_TARGET_CPU);
|
||||
// Load class names (one per line)
|
||||
this.classNames = Files.readAllLines(Paths.get(classNamesPath));
|
||||
// Check if model files exist
|
||||
Path cfgFile = Paths.get(cfgPath);
|
||||
Path weightsFile = Paths.get(weightsPath);
|
||||
Path classNamesFile = Paths.get(classNamesPath);
|
||||
|
||||
if (!Files.exists(cfgFile) || !Files.exists(weightsFile) || !Files.exists(classNamesFile)) {
|
||||
System.out.println("⚠️ Object detection disabled: YOLO model files not found");
|
||||
System.out.println(" Expected files:");
|
||||
System.out.println(" - " + cfgPath);
|
||||
System.out.println(" - " + weightsPath);
|
||||
System.out.println(" - " + classNamesPath);
|
||||
System.out.println(" Scraper will continue without image analysis.");
|
||||
this.enabled = false;
|
||||
this.net = null;
|
||||
this.classNames = new ArrayList<>();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Load network
|
||||
this.net = Dnn.readNetFromDarknet(cfgPath, weightsPath);
|
||||
this.net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
||||
this.net.setPreferableTarget(DNN_TARGET_CPU);
|
||||
// Load class names (one per line)
|
||||
this.classNames = Files.readAllLines(classNamesFile);
|
||||
this.enabled = true;
|
||||
System.out.println("✓ Object detection enabled with YOLO");
|
||||
} catch (Exception e) {
|
||||
System.err.println("⚠️ Object detection disabled: " + e.getMessage());
|
||||
throw new IOException("Failed to initialize object detection", e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Detects objects in the given image file and returns a list of
|
||||
@@ -736,9 +775,13 @@ public class TroostwijkScraper {
|
||||
* post‑processing【784097309529506†L324-L344】.
|
||||
*
|
||||
* @param imagePath absolute path to the image
|
||||
* @return list of detected class names
|
||||
* @return list of detected class names (empty if detection disabled)
|
||||
*/
|
||||
List<String> detectObjects(String imagePath) {
|
||||
if (!enabled) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> labels = new ArrayList<>();
|
||||
Mat image = Imgcodecs.imread(imagePath);
|
||||
if (image.empty()) return labels;
|
||||
|
||||
Reference in New Issue
Block a user