SAN ANTONIO – Smile, schoolchildren. You’re on calorie camera.

Health officials trying to reduce obesity and improve eating habits at five San Antonio elementary schools unveiled a $2 million research project Wednesday that will photograph students’ lunch trays before they sit down to eat and later take a snapshot of the leftovers.

A computer program then analyzes the photos to identify every piece of food on the plate — right down to how many ounces are left in that lump of mash potatoes — and calculates the number of calories each student ate.

The project, funded by a U.S. Department of Agriculture grant, is the first of its kind in the nation. The cameras, about the size of pocket flashlights, point only toward the trays and don’t photograph the students. Researchers say about 90 percent of parents gave permission to record every morsel of food their child eats.

“We’re trying to be as passive as possible. The kids know they’re being monitored,” said Dr. Roger Echon, who works for the San Antonio-based Social & Health Research Center, and who is building the food-recognition program.

Here’s how it works: Each lunch tray gets a bar code sticker to identify a student. After the children load up their plates down the line — cole slaw or green beans? french fries or fruit? — a camera above the cashier takes a picture of each tray.

When lunch is over and the plates are returned to the kitchen, another camera takes a snapshot of what’s left.

Echon’s program then analyzes the before and after photos to calculate calories consumed and the values of 128 other nutrients. It identifies foods by measuring size, shape, color and density.

Parents will receive the data for their children, and researchers hope eating habits at home will change once moms and dads see what their kids are choosing in school. The data also will be used to study what foods children are likely to choose and how much they’re eating.

Nine-year-old Aaliyah Haley went through the lunch line at W.W. White Elementary with cheesy enchiladas, Spanish rice, fat-free chocolate milk and an apple. Two cameras, one pointed directly down and another about tray-level, photographed her food before she sat down to eat.

“I liked it. It’s good food that was good for me,” Haley said.

Just how healthy it was researchers don’t know yet. Echon is still developing the program and expects to spend the first year of the four-year grant fine-tuning the equipment. By the 2012-13 school year, the Social Health & Research Center plans to have a prototype in place.

The database already includes about 7,500 different varieties of food. Echon said he started from scratch because there was no other food-recognition software to build upon.

He insisted on creating technology to record meals because asking 8-year-olds to remember what they ate and write it down is seldom accurate.

Researchers selected poor, minority campuses where obesity rates and diabetes risk are higher.