Skip to content

Commit 98e6725

Browse files
author
Anastasia
committed
Added minor code and README corrections
1 parent bf3d8cc commit 98e6725

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

DNN-OpenCV-Classification-with-Java/DnnOpenCV.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class DnnOpenCV {
2727
private static final String IMAGENET_CLASSES = "imagenet_classes.txt";
2828
private static final String MODEL_PATH = "models/pytorch_mobilenet.onnx";
2929

30+
private static final Scalar MEAN = new Scalar(0.485, 0.456, 0.406);
31+
private static final Scalar STD = new Scalar(0.229, 0.224, 0.225);
3032

3133
public static ArrayList<String> getImgLabels(String imgLabelsFilePath) throws IOException {
3234
ArrayList<String> imgLabels;
@@ -49,10 +51,6 @@ public static Mat centerCrop(Mat inputImage) {
4951
}
5052

5153
public static Mat getPreprocessedImage(String imagePath) {
52-
// define mean and standard deviation
53-
Scalar mean = new Scalar(0.485, 0.456, 0.406);
54-
Scalar std = new Scalar(0.229, 0.224, 0.225);
55-
5654
// get the image from the internal resource folder
5755
Mat image = Imgcodecs.imread(imagePath);
5856

@@ -73,13 +71,13 @@ public static Mat getPreprocessedImage(String imagePath) {
7371
imgFloat,
7472
1.0, /* default scalefactor */
7573
new Size(TARGET_IMG_WIDTH, TARGET_IMG_HEIGHT), /* target size */
76-
mean, /* mean */
74+
MEAN, /* mean */
7775
true, /* swapRB */
7876
false /* crop */
7977
);
8078

8179
// divide on std
82-
Core.divide(blob, std, blob);
80+
Core.divide(blob, STD, blob);
8381

8482
return blob;
8583
}

DNN-OpenCV-Classification-with-Java/README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,19 @@ sudo ldconfig
134134

135135
which creates the necessary links and cache to our freshly built shared library.
136136

137-
Rename the created Python3 bindings for OpenCV to `cv2.so`:
137+
Put ``lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so`` into the virtual environment installed packages:
138138

139139
```bash
140-
mv lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so cv2.so
140+
cp lib/python3/cv2.cpython-36m-x86_64-linux-gnu.so ~/env/lib/python3.7/site-packages/cv2.so
141141
```
142142

143-
Create a symlink of our OpenCV `cv2.so` into the virtual environment installed packages:
144-
145-
```bash
146-
cd env/lib/python3.7/site-packages/
147-
ln -s ~/opencv/build/cv2.so cv2.so
148-
```
149-
150-
The last step is to put ``~/opencv/build/lib/libopencv_java430.so`` to the ``/usr/lib`` directory:
143+
The last step is to put ``~/opencv/build/lib/libopencv_java430.so`` into the ``/usr/lib`` directory:
151144

152145
```bash
153146
sudo cp lib/libopencv_java430.so /usr/lib
154147
```
155148

156-
For Windows and macOS OpenCV Java build, please, follow the steps described in [Installing OpenCV for Java](https://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html).
149+
For Windows and macOS OpenCV Java build, please, follow the steps described in [Introduction to Java Development](https://docs.opencv.org/master/d9/d52/tutorial_java_dev_intro.html) or [Installing OpenCV for Java](https://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html).
157150

158151

159152
## Executing Model Conversion and Test Script

0 commit comments

Comments
 (0)