This paper presents TransitReID, a novel framework for collecting passenger origin-destination (OD) data essential for optimizing public transportation services. Existing methods, such as surveys, Bluetooth/Wi-Fi tracking, and automatic passenger counters, are costly, device-dependent, or difficult to match individual passengers. TransitReID automatically collects OD data by leveraging onboard surveillance cameras already installed in most public transportation vehicles. It introduces three key innovations: first, an occlusion-robust ReID algorithm that integrates a variational autoencoder-based region-attention mechanism and selective quality feature averaging to dynamically emphasize visible and distinctive body parts despite severe occlusion and viewpoint changes; second, a Hierarchical Storage and Dynamic Matching (HSDM) mechanism that transforms static gallery matching into a dynamic process to enhance robustness, accuracy, and speed in real-world bus operations; and third, a multi-threaded edge implementation that processes all data locally, enabling near-real-time OD estimation while protecting privacy. We also built a new TransitReID dataset consisting of over 17,000 images captured by front and rear bus cameras under various occlusion and viewpoint conditions. Experimental results show that TransitReID achieves state-of-the-art performance (88.3% R-1 accuracy, 92.5% mAP) and maintains 90% OD estimation accuracy in bus route simulations on NVIDIA Jetson edge devices.