Skip to content

Instantly share code, notes, and snippets.

@choowilson
Created February 24, 2020 03:50
Show Gist options
  • Save choowilson/683cdbfe4821c88fd853b54c2a78c73d to your computer and use it in GitHub Desktop.
Save choowilson/683cdbfe4821c88fd853b54c2a78c73d to your computer and use it in GitHub Desktop.
If you are using a pair of NativeImageLoader from DataVec and opencv's imshow. You need to divide the matrix by 255(normalize) first else only a white image will appear. If you use opencv imread and imshow as a pair then there will be no problem.
import org.datavec.image.loader.NativeImageLoader;
import org.nd4j.linalg.api.ndarray.INDArray;
import static org.bytedeco.opencv.global.opencv_highgui.*;
NativeImageLoader nil = new NativeImageLoader(416,416, 3);
INDArray image = nil.asMatrix("C:\\Users\\choowilson\\Desktop\\potato.jpg").div(255.0);
Mat mat = nil.asMat(image);
imshow("Output",mat);
waitKey(0);
destroyAllWindows();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment