Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add another datatype to check if it's easy to add another datatype #4

Merged
merged 6 commits into from
Sep 9, 2024

Conversation

Hennzau
Copy link
Collaborator

@Hennzau Hennzau commented Aug 8, 2024

Objective

This PR adds a new datatype for BBox to ensure that everything work well and it's easy to add a new datatype.

Datatypes & Usage

  • Image
use crate::image::Image;

let flat_image = (0..27).collect::<Vec<u8>>();
let image = Image::new_rgb8(flat_image, 3, 3, Some("camera.test")).unwrap();

let final_image = image.into_bgr8().unwrap();
let final_image_data = final_image.data.as_u8().unwrap();

let expected_image = vec![
    2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21,
    26, 25, 24,
];

assert_eq!(&expected_image, final_image_data);

use crate::image::Image;

let flat_image = vec![0; 27];
let original_buffer_address = flat_image.as_ptr();

let bgr8_image = Image::new_bgr8(flat_image, 3, 3, None).unwrap();
let image_buffer_address = bgr8_image.as_ptr();

let arrow_image = bgr8_image.into_arrow().unwrap();

let new_image = Image::from_arrow(arrow_image).unwrap();
let final_image_buffer = new_image.as_ptr();

assert_eq!(original_buffer_address, image_buffer_address);
assert_eq!(image_buffer_address, final_image_buffer);
  • BBox
use crate::bbox::BBox;

let flat_bbox = vec![1.0, 1.0, 2.0, 2.0];
let confidence = vec![0.98];
let label = vec!["cat".to_string()];

let bbox = BBox::new_xyxy(flat_bbox, confidence, label).unwrap();
let final_bbox = bbox.into_xywh().unwrap();
let final_bbox_data = final_bbox.data;

let expected_bbox = vec![1.0, 1.0, 1.0, 1.0];

assert_eq!(expected_bbox, final_bbox_data);

use crate::bbox::BBox;

let flat_bbox = vec![1.0, 1.0, 2.0, 2.0];
let original_buffer_address = flat_bbox.as_ptr();

let confidence = vec![0.98];
let label = vec!["cat".to_string()];

let xyxy_bbox = BBox::new_xyxy(flat_bbox, confidence, label).unwrap();
let bbox_buffer_address = xyxy_bbox.data.as_ptr();

let arrow_bbox = xyxy_bbox.into_arrow().unwrap();

let new_bbox = BBox::from_arrow(arrow_bbox).unwrap();
let final_bbox_buffer = new_bbox.data.as_ptr();

assert_eq!(original_buffer_address, bbox_buffer_address);
assert_eq!(bbox_buffer_address, final_bbox_buffer);

Quick Fixes

@Hennzau Hennzau added the enhancement New feature or request label Aug 8, 2024
@Hennzau Hennzau self-assigned this Aug 8, 2024
@Hennzau Hennzau force-pushed the other_datatype branch 5 times, most recently from 6438259 to c7c7006 Compare September 6, 2024 06:29
@Hennzau Hennzau changed the title Add other Datatypes inside Fastformat Add another datatype to check if it's easy to add another datatype Sep 6, 2024
@Hennzau Hennzau marked this pull request as ready for review September 9, 2024 09:22
@Hennzau Hennzau merged commit bf356e0 into main Sep 9, 2024
47 checks passed
@Hennzau Hennzau deleted the other_datatype branch September 9, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant