Created
July 9, 2019 14:51
-
-
Save ahmedfgad/0e8d12cdc3cd1e9b10f9e52ff85e0fb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package opencvapp; | |
import org.opencv.core.Core; | |
import static org.opencv.core.CvType.CV_32F; | |
import static org.opencv.core.CvType.CV_8U; | |
import org.opencv.core.Mat; | |
import org.opencv.ml.ANN_MLP; | |
public class OpenCVApp { | |
public static void main(String[] args) { | |
System.load("D:\\Opencv-4.1.0-vc14_vc15\\opencv\\build\\java\\x64\\" + Core.NATIVE_LIBRARY_NAME + ".dll"); | |
double[][] XORTrainArray = { | |
{0.0, 0.0}, | |
{0.0, 1.0}, | |
{1.0, 0.0}, | |
{1.0, 1.0} | |
}; | |
Mat XORTrain = new Mat(4, 2, CV_32F); | |
XORTrain.put(0, 0, XORTrainArray[0]); | |
XORTrain.put(1, 0, XORTrainArray[1]); | |
XORTrain.put(2, 0, XORTrainArray[2]); | |
XORTrain.put(3, 0, XORTrainArray[3]); | |
System.out.println("Train Inputs : \n" + XORTrain.dump()); | |
double[][] XORTrainOutArray = { | |
{0.0}, | |
{1.0}, | |
{1.0}, | |
{0.0} | |
}; | |
Mat XORTrainOut = new Mat(4, 1, CV_32F); | |
XORTrainOut.put(0, 0, XORTrainOutArray[0]); | |
XORTrainOut.put(1, 0, XORTrainOutArray[1]); | |
XORTrainOut.put(2, 0, XORTrainOutArray[2]); | |
XORTrainOut.put(3, 0, XORTrainOutArray[3]); | |
System.out.println("Train Labels : \n" + XORTrainOut.dump()); | |
ANN_MLP ANN = ANN_MLP.create(); | |
Mat layerSizes = new Mat(3, 1, CV_8U); | |
layerSizes.put(0, 0, 2); | |
layerSizes.put(1, 0, 2); | |
layerSizes.put(2, 0, 1); | |
ANN.setLayerSizes(layerSizes); | |
System.out.println("Layers Sizes : \n" + layerSizes.dump()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment