Info
This question is closed. Reopen it to edit or answer.
convert this code to efficient way.
2 views (last 30 days)
Show older comments
I have code that convert from org.bytedeco.javacv.Frame to matlab image.
In inefficient way. Can you help me convert it to efficient way?
javaaddpath('javacv.jar')
import org.bytedeco.javacv.*;
import org.bytedeco.javacpp.*;
grabber = FrameGrabber.createDefault(0)
grabber.start()
img = grabber.grab()
buff = img.image(1);
% //from here is inefficient code
charBuff = buff.asCharBuffer;
n = charBuff.length;
data = repmat(uint16(0),n,1);
for i=0:n-1
data(i+1) = charBuff.get(i);
end
I = typecast(data, 'uint8');
I = cat(3, ...
reshape(I(3:3:end),[w h])', ...
reshape(I(2:3:end),[w h])', ...
reshape(I(1:3:end),[w h])' ...
);
imshow(I);
1 Comment
dpb
on 29 Aug 2015
Don't know what the form of buff is but why wouldn't
I=typecast(buff.asCharBuffer,'uint8');
be the same as what your end result is? Although I'd think there's likely a direct transformation if one knew the input format and what one's trying to get to in description rather than code...but I'm not an image processing guy at all, either, so what do I know??? :)
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!