Add a public from_tensor builder to OcrInput#159
Add a public from_tensor builder to OcrInput#159Henauxg wants to merge 1 commit intorobertknight:mainfrom
from_tensor builder to OcrInput#159Conversation
|
If you have an let mut tensor = NdTensor::zeros([chans, width, height]);
// Fill tensor
let image_source = ocr_engine.prepare_input(ImageSource::from_tensor(tensor.view()));
// Pass source to OCR engine methodsThe one downside of this is that Is the issue here that it wasn't clear how to get an |
|
I have been too hasty to discard the let offset = CHANNELS_COUNT * (rect.origin.y * frame.width + rect.origin.x);
let storage = frame.data[offset as usize..frame.data.len()].into_storage();
let layout = NdLayout::from_shape_and_strides(
[
rect.size.height as usize,
rect.size.width as usize,
CHANNELS_COUNT as usize,
],
[
(frame.width * CHANNELS_COUNT) as usize,
CHANNELS_COUNT as usize,
1,
],
OverlapPolicy::AllowOverlap,
)?;
let tensor_view = NdTensorView::from_storage_and_layout(storage, layout);
let img_src = ImageSource::from_tensor(tensor_view, DimOrder::Hwc)?;
let ocr_input = engine.prepare_input(img_src)?;Thank you for your time and sorry for the inconvenience, |
You are correct that there is no copy when creating let img_src = NdTensorView::from_data(shape, slice)Where
There is no problem at all. I'm sure this issue will be a useful reference for someone else in future :) |
|
For reference, I don't think that this last builder can by used in my case as I am not using the default strides (stride on the Y axis has to account for the offset between each byte being larger than rect.width due to the rect being a sub-region of the whole frame) |
Thank you for the library,
I have a situation where I want to prepare the image (as in
prepare_image) from a custom data source that is not backed by anImageSourceorNdTensorView. But currently, the only way to prepare the input/create anOcrInputis from anImageSourcevia ``prepare_input`.This PR adds a
from_tensorbuilder toOcrInputwhich allows to have a custompreparestep to build a tensor, and then transform it to anOcrInput.