Verifying E-commerce Promotion Transparency with OCR and Data Scraping

The Promotion Mechanism

Following a product launch, a manufacturer initiated a campaign promising rewards to the first 1,000 users who posted a valid review with a photo. After purchasing a tablet and participating in the event, the verification process became the primary focus. The organizer claimed to publish a list of winning order IDs on a specific date.

Challenge of Image-Based Data

Upon checking the announced results, the winning list was presented as a static long image containing only serial numbers, order IDs, and user IDs. This format renders the data unsearchable, making it manually impractical to verify a specific order among 1,000 entries. To address this, an automated approach using Optical Character Recognition (OCR) was considered to extract text from the image.

Implementing OCR with Baidu Cloud SDK

The objective was to utilize an OCR SDK to digitize the content of the winning list image. Using the Baidu Cloud OCR Java SDK, a client was initialized to handle image recognition requests. The implementation requires specific API credentials to authenticate the client.

import com.baidu.aip.ocr.AipOcr;

public class OcrConfig {
    // Set constants for API credentials
    private static final String APP_ID = "YOUR_APP_ID";
    private static final String API_KEY = "YOUR_API_KEY";
    private static final String SECRET_KEY = "YOUR_SECRET_KEY";

    public static AipOcr getClient() {
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
        // Optional: Set connection timeout parameters
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        return client;
    }
}

Image Segmentation for Batch Processing

Initial tests revealed that uploading the entire high-resolution list image at once caused API failures due to size limits. To resolve this, a pre-processing step was implemented to slice the large image into smaller, manageable tiles. The following utility class handles the segmentation by dividing the source image into a grid of smaller JPEG files.

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ImageSlicer {

    public static void sliceImage(File sourceFile, int rows, int cols, File outputDir) throws IOException {
        if (!sourceFile.exists() || !sourceFile.isFile()) {
            throw new IllegalArgumentException("Invalid source file");
        }

        BufferedImage originalImage = ImageIO.read(sourceFile);
        int totalWidth = originalImage.getWidth();
        int totalHeight = originalImage.getHeight();

        int tileWidth = totalWidth / cols;
        int tileHeight = totalHeight / rows;

        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }

        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < cols; c++) {
                BufferedImage subImage = originalImage.getSubimage(
                    c * tileWidth, 
                    r * tileHeight, 
                    tileWidth, 
                    tileHeight
                );
                File tileFile = new File(outputDir, "part_" + r + "_" + c + ".jpg");
                ImageIO.write(subImage, "jpg", tileFile);
            }
        }
    }
}

Transition to API Data Scraping

Before the OCR pipeline could be executed, the organizer removed the winning list image from the campaign page. Consequently, the strategy shifted to verifying eligibility based on the campaign rules, which stated that rewards were given to the first 1,000 valid reviews based on system time. By inspecting network traffic in the browser developer tools, an API endpoint returning review data in JSON format was identified.

The response payload contained a ctime field representing the submission timestamp. A custom scraper was developed to retrieve all available reviews, parse the timestamps, and determine the ranking of a specific user's submission.

import java.util.*;
import java.util.stream.Collectors;

public class ReviewAnalyzer {

    // Simulated review data structure
    static class Review {
        String username;
        long timestamp; // Unix timestamp in seconds
        String content;

        public Review(String username, long timestamp, String content) {
            this.username = username;
            this.timestamp = timestamp;
            this.content = content;
        }
    }

    public static void main(String[] args) {
        List<Review> allReviews = fetchReviewsFromApi(); // Assume this fetches data
        String targetUser = "target_username";

        // Sort reviews by timestamp ascending
        List<Review> sortedReviews = allReviews.stream()
                .sorted(Comparator.comparingLong(r -> r.timestamp))
                .collect(Collectors.toList());

        // Find target rank
        int rank = -1;
        for (int i = 0; i < sortedReviews.size(); i++) {
            if (sortedReviews.get(i).username.equals(targetUser)) {
                rank = i + 1;
                break;
            }
        }

        if (rank > 0 && rank <= 1000) {
            System.out.println("User is eligible. Rank: " + rank);
        } else {
            System.out.println("User not in top 1000. Rank: " + (rank == -1 ? "Not Found" : rank));
        }
    }

    private static List<Review> fetchReviewsFromApi() {
        // Placeholder for actual HTTP request logic
        return new ArrayList<>();
    }
}

Data Analysis and Findings

Executing the analysis on 3,751 retrieved reviews revealed that the specific user's comment was posted at a timestamp that ranked it 959th chronologically. This position theoretically falls within the winning range. However, the user's order ID did not appear on the (now removed) official image list. This discrepancy suggests potential inconsistencies in how the "first 1,000" metric was calculated or displayed by the platform.

Further analysis of the dataset allowed for determining sales distribution by product model and generating word clouds from review text to visualize customer sentiment. Additionally, the exploration of OCR capabilities extended to other computer vision tasks, such as colorizing grayscale photographs and applying anime-style filters to portraits, utilizing the same SDK infrastructure.

Tags: OCR java Data Scraping Image Processing API analysis

Posted on Sat, 26 Sep 2026 16:11:34 +0000 by Tjeuten