If the law allowed, an Oklahoma judge would “castrate” a perv accused of secretly recording a “staggering” number of victims — including children and teens — in their homes, she said this week.

Ryan Alden — now facing a life sentence — was working for a company that installed security systems in people’s homes when investigators found cameras hidden behind vents pointing into children’s bedrooms and bathrooms at two residences, in Nichols Hills and Oklahoma City, local outlet KFOR reported.

During Alden’s sentence hearing Wednesday, a state prosecutor revealed that investigators searched Alden’s electronic devices and found various videos of even more victims — many yet to be identified.

The videos could fill up 12 spindles of compact disks, an Edmond Police Department officer testified, according to the report.

In addition to the bedroom and bathroom videos, Alden had allegedly taken secret video up women’s skirts at restaurants, athletic centers and even churches around the Oklahoma City metro area, the outlet reported.

Alden’s defense attorney argued that Judge Amy Palumbo should give him a five- to 10-year prison sentence followed by life probation — and put up a counselor who evaluated him, determining that he was treatable.

But Palumbo wasn’t swayed.

“If the law allowed me to have you castrated, I would,” she blasted Alden in court.

If Alden was released, Palumbo argued, he’d likely commit the crimes again.

In some of the teen victims’ statements, read in court, they said they would always wonder if their images were floating around on the internet. Several said they’d need years of therapy to process the trauma, the outlet reported.

Alden told the local station that he thought the life sentence was “probably” fair.

“With everything I did, yes, but I can’t, I don’t know for sure,” the accused perv said.

“I’m just truly sorry,” he added. “That’s all I can say.”