In the past decades, the increasing scale of intensive pig farms led farmers to use automatic tools to monitor the welfare and health of their animals. Visual observation and manual monitoring, usually practiced in small-scale farms, is unreliable in large-scale husbandry, and is expensive and time consuming. Environmental parameters are crucial information for the efficient management of piggery buildings, as they have a significant effect on production efficiency, health and welfare of confined animals. The aim of the present study was to evaluate the relationship between pig activity and environmental parameters in a pig building by means of image analysis. The barn for 350 fattening pigs was open-space, mechanically ventilated and subdivided into 16 pens with fully slatted floor. The room was equipped to monitor the ventilation rate, internal and external temperature and relative humidity every minute. For the experiments, two adjacent pens were selected, each 5.9 by 2.6 m, with ~16 pigs in each. Pigs were continuously monitored during 30 days using an infrared-sensitive CCD camera that was mounted 5 m above the floor. Recorded data were processed in real time by Eyenamic, an innovative software that continuously and automatically registers the behaviour of a group of animals, intended as the activity and occupation indices of the pigs. A preliminary virtual subdivision of the two pens in four zones (two zones for each pen) was performed to evaluate differences in activity/occupation indices in ‘front’ and ‘back’ zones of the pen. Recorded images were visually observed in the laboratory to estimate pig activity type in relation to the indices calculated by Eyenamic software. The occupation index showed higher values (up to 0.75 units) in Zones 1 and 4 placed near the corridor. There was a significant relation between pig occupation index measured in the two pens and ventilation rate, temperature and humidity. The interaction between ventilation and humidity and temperature and humidity significantly affected pig movements during the day. Pigs tended to stay in the part of the pen far from the external wall, where air velocity was higher, probably because this is a ‘central zone’ in the barn, characterised by a reasonable air movement (~0.30 m/s). On the contrary, the part of the pen nearest to the external wall, characterised by a humid floor surface and by a limited air speed, was occupied by animals at the trough mainly during feeding times and for defecation and urination.