If you're using a Code action and using PHP you can call the group function on the object to get its group. Example as follows.
$group = $variables['var1']->group();
There isn't a way to easily access the category id from substitutions from a photo object. You can try using format functions, but unsure if it will work. To give it a try enable format functions under Parameters then give the below a try.
[cb:parse function="group" class="var1" method="get" get="category" /]
That should call the group function on var1 (photo object) then call the get function on that group and pass category as the first variable to that get function which should return category id.