Closed franferraz98 closed 2 years ago
The rest of the code, for if it's needed:
import logging
import math
import random
from pathlib import Path
import random
import numpy as np
import bpy
import zpy
from mathutils.bvhtree import BVHTree
log = logging.getLogger("zpy")
def rotation_matrix(axis, theta):
"""
Return the rotation matrix associated with counterclockwise rotation about
the given axis by theta radians.
"""
axis = np.asarray(axis)
axis = axis / math.sqrt(np.dot(axis, axis))
a = math.cos(theta / 2.0)
b, c, d = -axis * math.sin(theta / 2.0)
aa, bb, cc, dd = a * a, b * b, c * c, d * d
bc, ad, ac, ab, bd, cd = b * c, a * d, a * c, a * b, b * d, c * d
return np.array([[aa + bb - cc - dd, 2 * (bc + ad), 2 * (bd - ac)],
[2 * (bc - ad), aa + cc - bb - dd, 2 * (cd + ab)],
[2 * (bd + ac), 2 * (cd - ab), aa + dd - bb - cc]])
def rotate(point, angle_degrees, axis=(0,1,0)):
theta_degrees = angle_degrees
theta_radians = math.radians(theta_degrees)
rotated_point = np.dot(rotation_matrix(axis, theta_radians), point)
return rotated_point
That is a weird result for sure. Code seems to looks fine. What do the depth and segmentation images look like for those weird bounding boxes?
I deleted those ones, but here are some new ones:
In general they look fine, I wouldn't say that it has to do with the model.
Interesting. Are you using your own visualization tools to show the bounding box over the image? There are a couple different styles of bounding boxes, zpy uses (x, y, width, height)
as seen here. Could be that your visualization tool uses something else like (x1, y1, x2, y2)
Yes, I use my own script, but I'd say I got the style you say. Here is my script:
import json
import argparse
import cv2
from matplotlib import pyplot as plt
# Initiate argument parser
parser = argparse.ArgumentParser(
description="Sample TensorFlow COCO-to-TFRecord converter")
parser.add_argument("-a",
"--ann_file",
help="Path to the folder where the input .coco.json files are stored.",
type=str)
parser.add_argument("-i",
"--img_dir",
help="Path to the folder where the input image files are stored. "
"Defaults to the same directory as ANN_FILE.",
type=str, default=None)
args = parser.parse_args()
if args.img_dir is None:
args.img_dir = args.ann_file
img_dir=args.img_dir
annotations_file=args.ann_file
# Remove annotations
# Read JSON for annotations
d = {}
with open(args.ann_file) as f:
d = json.load(f)
f.close()
# Get images and annotations
images = d['images']
annotations = d['annotations']
for i in images:
print("PATH: ", args.img_dir + i['file_name'])
img = cv2.imread(args.img_dir + i['file_name'])
for a in annotations:
if i['id'] == a['id']: # Annotation for the image
[x,y,w,h] = a['bbox']
start = (int(x), int(y))
end = (int(x+w), int(y+h))
color = (255,0,0)
thick = 2
cv2.rectangle(img, start, end, color, thick)
cv2.imshow(' ',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Well yeah, it was my fault. That i['id'] == a['id']
should be i['id'] == a['image_id']
.
Sigh. Sorry, had my head somewhere else when I wrote this. Thanks for your support!
All good! Glad I could help.
I've created this Blender scene where I have a dice, and I'm using ZPY to generate a dataset composed of images obtained by rotating around the object and jittering both the dice position and the camera. Everything seems to be working properly, but the bounding-boxes generated on the annotation file get progressively worse with each picture.
For example this is the first image's bounding-box:
This one we get halfway through:
And this is one of the last ones:
This is my code (I've cut some stuff, I can't paste it all for some reason):
Is this my fault or an actual bug?