Every gold loan branch has CCTV. Most of it is never watched. Before I start let me be honest. I am not a computer vision or video expert. I relied heavily on AI tools and Codex to build most of what you will read here.

The cameras are there because security teams, the insurer and the auditor want them there. Footage sits on an NVR in a back room. It gets pulled only after something goes wrong. By then it is too late.

I asked a simple question. What if the cameras worked for me every minute, not just after any security incident?

So I built an internal AI platform. It uses computer vision, the part of AI that lets software understand images and video. It takes the same CCTV feed every branch already has. It watches for the events that matter in a gold loan branch. Then it checks those events against my LOS and LMS. When the camera and the system don't agree, I get an alert.

This post is how I did it. I start with the raw feed, then the pipe to the cloud, then the use cases.

Branch surveillance dashboard with a live CCTV feed, person tracking box, loan and gold custody numbers, walk-in and vault counters, all fictional
Branch view with live camera tracking

Step 1: The raw feed

A typical branch has 6 to 10 IP cameras on an NVR from Hikvision, Dahua or CP Plus.

Each camera gives an RTSP stream. I find and set up cameras using ONVIF.

rtsp://user:pass@192.168.1.64:554/Streaming/Channels/101

Every camera sends two streams:

StreamResolutionFrame rateBitrateUse
Main1080p to 4MP15 to 25 fps2 to 4 MbpsEvidence, small details like an XRF screen
Sub640x3605 to 15 fps256 to 512 kbpsLive detection

On every camera I set:

  • H.264 or standard H.265. Vendor "H.265+" is off, it breaks decoders.
  • One I-frame every second, for clean cuts.
  • NTP time sync. Every rule depends on time.

Why HLS

RTSP needs open ports and breaks on weak internet. So I convert it to HLS: 2 to 6 second chunks plus an .m3u8 playlist. LL-HLS brings live delay down to 2 to 3 seconds.

This gives me control:

  • Every chunk has a time. I can pull “vault camera, 11:42 to 11:47”.
  • It is plain HTTP. Easy to store, cache and replay.
  • No re-encoding. One small box handles a whole branch.

Step 2: Getting it to Cloudflare

Each branch has a small edge box next to the NVR. It runs MediaMTX and FFmpeg to turn RTSP into HLS.

The box connects through Cloudflare Tunnel (cloudflared). It is outbound only. No open ports, no public IP, and it reconnects by itself.

  • R2 stores the chunks. No egress fee, so audit replays cost nothing extra.
  • Cloudflare Access protects live views with company SSO. Every view is logged.
  • Workers and Queues pass each new chunk to my vision service.

The sub stream goes up live. The main stream stays on the box and goes up only for clips I need. A local buffer covers internet outages.

Step 3: The platform on top

The video is only raw material. The real product is a timeline of events, matched against my loan systems.

Pipeline from branch IP cameras and edge box through Cloudflare Tunnel, R2 and Queues to the vision service, event timeline and rules engine that matches video with LOS and LMS
Branch CCTV to alerts. The full pipeline

The platform has three parts.

  • Vision service. It reads the HLS chunks. It finds people and tracks them across cameras. It watches the zones I draw for each branch: entrance, vault door, appraisal desk, XRF machine, sealing table, counters. For small text, like an XRF screen, it pulls the main stream clip and runs OCR. I use open-source AI models like YOLO for detection, with a tracker on top. Staff faces are enrolled once for attendance.
  • Event timeline. Every detection becomes a simple event: branch, camera, zone, time, what happened, who. For example, "vault door opened, 11:42:10, two staff present". All cameras of a branch share one clock, so I can follow a packet or a customer from one camera to the next.
  • Rules engine. This is where the value is. It pulls loans, closures and stage times from the LOS and LMS. Then it checks each event against them. A vault opening with no transaction is an alert. A loan booked at a purity the XRF did not show is an alert. Every alert carries the clip.

The nice part is that a new use case is usually just a new zone and a new rule. The pipe stays the same.

What we detect

Each use case follows the same pattern. The camera sees an event. The system has a record. I compare the two. A mismatch becomes an alert.

1. Walk-ins

The entrance camera counts every person who comes in. Staff are known faces, so they are not counted. I track each customer from entry to exit.

Then I compare walk-ins with leads and loans created in the LOS for that day. If 40 people walked in and only 12 loans were opened, I want to know why. Was it rate? Purity? Wait time? Staff behaviour? It also tells me which branches lose customers at the door.

2. Attendance

Staff faces are enrolled once in an AI face recognition model. The camera marks the first time I see someone in the morning and the last time in the evening. No biometric machine. No proxy punching.

I also catch long gaps. For example, the branch manager left at 2 pm and came back at 5 pm.

3. Vault opening

I draw a zone on the vault door. The system knows when the door opens and closes, and who was standing there.

Every opening must have a reason in the LMS:

  • a new loan, where a packet goes in
  • a closure or release, where a packet comes out
  • a scheduled audit

If the vault opens and there is no matching transaction in a time window around it, I raise an alert. The alert comes with the clip. A regional manager can see in 30 seconds what happened.

I also check the dual custody rule. My process needs two people for the vault. One person alone at an open vault is an alert.

4. Packets in and out

This was the hardest one. A packet moves through several cameras: the appraisal desk, the sealing table, the walk to the vault, the vault itself. No single camera sees the full journey.

So I stitch events from several cameras on one timeline. Each step is counted. At the end of the day I run an audit:

  • packets sealed today vs new loans in the LMS
  • packets that went into the vault vs packets sealed
  • packets taken out vs closures and releases

If the numbers don’t match, the branch gets an alert that evening, not at the next quarterly audit.

5. Gold assaying and the XRF machine

I watch the assaying desk. The system checks:

  • Was the gold actually put in the XRF machine? For how long?
  • Was the touchstone or acid test done where my process says it should be?
  • Was the customer present while the gold was tested and weighed?
  • Was each item tested, or only one from the lot?

I also read the XRF screen using an AI OCR model on the main stream clip. Then I match the purity and weight with what was entered in the LMS. If the XRF said 20K and the loan was booked at 22K, that is a flag.

This connects to my collateral audit work. The camera tells me if the first assessment was done right. The audit tells me if a second check agreed.

6. Loan TAT, stage by stage

I know when the customer walks in and when they walk out. In between, they sit in zones: waiting area, KYC desk, appraisal desk, cash or disbursal counter.

The LOS has its own timestamps for each stage. I put both on one timeline. This shows me where the time really goes.

What I learned surprised me. The LOS said appraisal took 8 minutes. The camera said the customer waited 25 minutes before anyone looked at the gold. The system clock only starts when staff click a button. The customer’s clock starts at the door.

Other things the same feed can do

Once the pipe is in place, each new use case is mostly a new rule. These are the ones I think are worth it for any gold loan branch.

  • Customer identity check. Match the face at the desk with the KYC photo in the LOS. This catches impersonation, where one person pledges gold in someone else's name.
  • Repeat pledgers across names. The same face showing up for loans under different names or at different branches. A strong signal for benami loans or stolen gold.
  • Camera health and tampering. A camera covered, turned away, out of focus or offline. Today this is found weeks later. I find it in minutes.
  • After-hours movement. Any person or motion in the branch after closing, or near the vault at night. Straight to the security team.
  • Branch open and close times. When the shutter actually went up, vs the official time.
  • Queue length and staffing. How many customers are waiting and for how long. Helps decide where to add a person on busy days.
  • Unauthorised people in the back office. A customer or outsider entering the appraisal or vault area.
  • Phones near packets. A phone in hand while handling open gold. Useful for training and for spotting odd behaviour.
  • Gold seen leaving with the customer. On a new loan, the gold should stay. On a closure, it should go. The exit camera can check which one happened.

Why I didn't buy it off the shelf

I tested several third-party video analytics products first. None of them fit. The reasons were the same every time.

  • They are built for retail and security. People counting, heatmaps, intrusion. Useful, but generic. None knew what a vault, a gold packet or an XRF machine is.
  • They can't talk to my systems. The value is not in the video. It is in the join between the video and the LOS and LMS. No vendor would build that for me.
  • They alert on events, not on mismatches. "Vault door opened" is noise. "Vault door opened with no loan or closure" is a signal. That rule needs my data.
  • Pricing is per camera, per month. Across all my branches and cameras, the bill grows fast. My own stack costs a mini PC per branch plus cloud storage.
  • Many need new cameras or their own NVR. I wanted to use what was already installed.
  • Black-box models. When an alert is wrong, I need to see why and fix it myself.
  • Weak internet was an afterthought. Most assumed a good, steady connection. My branches don't always have one.
  • Data control. Customer faces and gold handling footage are sensitive. I wanted to know exactly where they are stored and who can see them.

What I learned

  • Fix the clocks first. Every rule depends on time. NTP on every camera and NVR is not optional.
  • Draw zones by hand, per branch. Every branch layout is different. Ten minutes of setup saves weeks of false alerts.
  • Start with mismatch rules, not detection. With AI, detecting a door is easy. Knowing that it should not have opened is the useful part.
  • Send the clip with the alert. An alert without video gets ignored. A 30-second clip gets acted on.
  • Tell staff and customers. Put up clear notices. Explain to staff what is tracked and why. Follow the DPDP Act on how long you keep faces and who sees them.
  • It is not about catching people. Most alerts are process gaps, not fraud. The camera shows where my own process is weak.

The cameras were already there. The NVR was already there. I only added a small box, a tunnel, a few AI models and my own logic on top. Now the branch talks to me all day, not just after something goes wrong.