Перейти к содержимому

Как подключить opencv к intellij idea

  • автор:

Не получается подключить OpenCV для android-SDK в Intellij IDEA, gradle

Доброе время суток. Уже кучу времени мучаюсь с проблемой подключения OpenCV для android в среду Intellij IDEA. Делала все по этой инструкции: https://habr.com/post/262089/. Она для Anroid Studio, но для IDEA я инструкции не нашла. Скачала с офф сайта последнюю версию OpenCV для android, скопировала папку java, добавила библиотеки в jniLibs, прописала зависимость от импортированного модуля. Поменяла циферки с версиями в AndroidManifest у импорт. модуля, но build.gradle — который в инструкции тоже сказано поменять — в папке java отсутствовал. Скопировала пример из той ссылки (то же самое, что и там): Activity:

 package мой пакет; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.SurfaceView; import android.view.WindowManager; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; import R из моего пакета; public class ActivityOpenCVTest extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 < private CameraBridgeViewBase mOpenCvCameraView; @Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_opencv_test); mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.view); mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); mOpenCvCameraView.setCvCameraViewListener(this); >@Override public void onPause() < super.onPause(); if (mOpenCvCameraView != null) mOpenCvCameraView.disableView(); >@Override public void onResume() < super.onResume(); OpenCVLoader.initDebug(); mOpenCvCameraView.enableView(); >public void onDestroy() < super.onDestroy(); if (mOpenCvCameraView != null) mOpenCvCameraView.disableView(); >public void onCameraViewStarted(int width, int height) < >public void onCameraViewStopped() < >public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) < return inputFrame.rgba(); >> 
                      . всякие другие активности, включая рассматриваемую ActivityOpenCVTest  

В итоге сборка прошла успешно, но выскочил Warning «Gradle: module ‘<этот модуль>‘ won’t be compiled. Unfortunately you can’t have non-Gradle Java module and Android-gradle module in one project» . Плюс еще в манифесте импортированного модуля подчеркивается красным xmlns:android=»http://schemas.android.com/apk/res/android» а так же android versionCode и versionName При попытке запустить на устройстве выдаются такие вот ошибки:

Error:(8, 26) error: package org.opencv.android does not exist Error:(9, 26) error: package org.opencv.android does not exist Error:(10, 23) error: package org.opencv.core does not exist Error:(16, 40) error: package CameraBridgeViewBase does not exist Error:(20, 12) error: cannot find symbol class CameraBridgeViewBase Error:(62, 50) error: package CameraBridgeViewBase does not exist Error:(62, 12) error: cannot find symbol class Mat Error:(27, 30) error: cannot find symbol class CameraBridgeViewBase Error:(46, 9) error: cannot find symbol variable OpenCVLoader Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 

Очевидно, что модуль не может подключиться без gradle, но я не знаю, как грамотно сделать gradle-модуль из простого модуля в Intellij IDEA. Или как иначе импортировать библиотеку OpenCV. Пожалуйста, помогите решить эту проблему.

Как подключить opencv к intellij idea

|WORK| Intellij Add To Java Library Path

intellij java library path, intellij set java.library.path, add dll to java.library.path intellij, no sqljdbc_auth in java.library.path intellij, set java library path intellij idea, add java.library.path intellij, how to add dll file to java library path in intellij, no ocijdbc12 in java.library.path intellij, java.library.path intellij idea, java.library.path windows intellij, intellij idea java.library.path, intellij add java.library.path, intellij change java.library.path, intellij specify java.library.path, intellij idea set java library path, intellij no in java.library.path, intellij vm options java.library.path, intellij no ocijdbc12 in java.library.path

Intellij Add To Java Library Path ★★★★★ DOWNLOAD

The lib folder above is the directory that contains the JavaFX jar files needed for . Adding Java Sources to the JavaFX IntelliJ IDEA Project.. My attempts to add the property under VMargs (as -Djava.library.path=C:/path/to/my/dlls) didn’t work and neither did adding it to the JVM startup . So I’m trying to add the native libraries to the IntelliJ IDEA project. Easy enough, go to the . Error message: no bulletjme in java.library.path at com.jme3.system.. solition : ==>Right click on the Project ==>Properties ==>Click on RUN ==>VM Options : -Djava.library.path=»C:\Your Directory where Dll is present» ==>Ok.. . родные библиотеки в Java, вам нужно указать свойство java.library.path, чтобы. . IntelliJ IDEA 12 для разработки приложений OpenCV 2.4.5 на Java. . add compile ‘com.github.ctodobom:OpenCV-3.1.0-Android:-SNAPSHOT’ Это . Add a library to module dependencies From the main menu, select File | Project Structure Ctrl+Shift+Alt+S and select Modules. Open the Dependencies tab and click . Select a library you want to add and click Add Selected at the bottom of the dialog.. Learn more about java, api, matlab engine, nativemvm MATLAB. . the suggestion to add matlabroot\bin\win64 to the PATH permanently using the Windows UI, . my IntelliJ IDE after changing the PATH on the Windows Environment Variables .

UnsatisfiedLinkError: no opencv_java320 in java.library.path» . If you’re using IntelliJ IDEA you should add OpenCV library as Native Library . If you run your program from IntelliJ then you can set the java.library.path in the VM options input field in the Run/Debug Configurations dialog. enter image . When constructing a new Java project in IntelliJ IDEA, the following . Path; Click on Configure Build Path; Click on Libraries and select Add External JARs; Select the jar file from the required folder; Click and Apply and OK . Then we add the needed jar files by going to File -> Project Structure: IntelliJ . UnsatisfiedLinkError: no lwjgl(64) in java.library.path. IntelliJ . Select Properties and then, move to the Run tab. In the VM Options field, add the following option, based on your library’s path: java -Djava.library.. The project structure and Java classes available to manage projects and modules . A project defines collections referred to as modules and libraries. . for the project, you can create a single-module or a multi-module project.. I want to configure IntelliJ IDEA to include my dependency jar files. . Preferences -> Java -> Build Path -> User Libraries -> New(Name it) -> Add external Jars . Right click on your project and choose Build Path -> Add Library.. Native library — — constant no *library_name* in java.library.path. Follow . Tried adding it via File->Project Structure -> LIbraries -> add -> java .

Main | VM params: -Dazureus.config.path=»C:\SVN\DemoPlugin\src\config» -Djava.library.path=»C:\SVN\DemoPlugin\lib»; Create the output dir for your plugin.. tdlib folder after the build Java. it looks like fine but I have two another problem. how to run the project from IntelliJ? I add java.library.path=/ . In the IntelliJ IDE, you add the LeapJava.jar file to a project as a library. You separately set the path to the Leap Motion native libraries using the JVM parameter, . path=/path/to/directory/with/dll in your run configuration. View entire discussion ( 5 comments). More posts from the IntelliJIDEA community.. В статье рассмотрено как подключить библиотеку с нативным кодом в IntelliJ Idea, что такое java.library.path и для чего он нужен.

Работа с OpenCV. Часть 1. Установка и Hello World

Все ниже описанное сделано под управлением Linux Ubuntu 12.04!
Первым делом посещаем сайт JavaCV и скачиваем последную версию, далее смотрим на поддерживаемую версию OpenCV в разделе Required Software это OpenCV 2.4.6.x.
Идем на сайт OpenCV и скачиваем поддерживаемую на данный момент версию.

Если все прошло успешно у нас будет 2 архива:
opencv-2.4.6.1.tar.gz
javacv-0.6-bin.zip

Установка OpenCV

Для работы графики дополнительно нужно установить (ну и cmake если вдруг у кого-то не стоит):
apt-get install libgtk2.0-dev
apt-get install cmake

Команды для установки:
cd opencv-2.4.6.1/

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ./
на этапе cmake важно просмотреть вывод консоли и найти такие строчки:

Java:
— ant: /usr/bin/ant (ver 1.8.2)
— JNI: NO
— Java tests: NO

Без JNI вы не получите JAR файл который нам нужен, если вы увидели тоже что и я, то проверьте вашу $JAVA_HOME, скорее всего она пуста… В идеале вы должны увидеть следующее:

— Java:
— ant: /usr/bin/ant (ver 1.8.2)
— JNI: /usr/lib/jvm/java-8-oracle/include /usr/lib/jvm/java-8-oracle/include/linux /usr/lib/jvm/java-8-oracle/include
— Java tests: YES

Продолжаем дальше:
make
make install
А пока они выполняются можно пойти и сделать себе кофе!

Работа в IDE

Создаем обычное Java-приложение, и добавляем туда такие библиотеки:
javacv.jar
javacpp.jar
javacv-linux-*.jar

И попробуем вывести трансляцию веб-камеры в окно, и еще сохранить фото:

package Habr; import com.googlecode.javacv.CanvasFrame; import com.googlecode.javacv.FrameGrabber; import com.googlecode.javacv.cpp.opencv_core.*; import com.googlecode.javacv.OpenCVFrameGrabber; import static com.googlecode.javacv.cpp.opencv_core.cvFlip; import static com.googlecode.javacv.cpp.opencv_highgui.*; public class HelloWorld < public static void main(String[] args) < CanvasFrame canvas = new CanvasFrame("Webcam"); canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); FrameGrabber grabber = new OpenCVFrameGrabber(""); try < grabber.start(); IplImage img; while (true) < img = grabber.grab(); canvas.setCanvasSize(grabber.getImageWidth(), grabber.getImageHeight()); if (img != null) < cvFlip(img, img, 1); cvSaveImage("/home/vlad/1.jpeg", img); canvas.showImage(img); >> > catch (Exception e) < >> > 

После запуска можно увидеть себя, а потом найти фото по указанному пути 🙂 Я думаю объяснять что такое OpenCV, и что он может не надо. Спасибо, это все.

How to set-up OpenCV in Intellij IDEA

After searching for about an hour on how to set up OpenCV in IntelliJ IDEA, and not finding a good solution for beginners, I’ve decided to post it myself. I am not an expert, clearly, just started learning Java and have no experience with IntelliJ IDEA. So, there might be a better solution than this but I didn’t find one.

I assume that you have already downloaded and installed OpenCV and IntelliJ IDEA. Create a new project.

Go to File > Project Structure.

Select Modules from the side panel and the slect the Dependencies tab. Click the + icon on the right to add a dependency. Then select the Add Jar/Directory option.

Then browse to the path where you installed the OpenCV and select build/java/opencv-***.jar and click OK.

It will be shown as dependency in the window. Now, we also have to add the Native Library Location. To do that, double click on the opencv-310.jar (currently selcted in the image above).

Then click on the + icon to add the Native Library Location.

And then browse to the locatoin where you installed OpenCV and select build/java/x64. You should select x64 or x86 based on your system specification. Now click OK.

This will add Native Library Location to the dependency. Now click OK and apply the changes.

Here is a test to check whether your setup worked or not.

Remeber to include the highlighted line of code to load the library, otherwise it will not compile.

Here is the code.

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;

public class Test // Compulsory
static< System.loadLibrary(Core.NATIVE_LIBRARY_NAME); >

public static void main(String[] args) System.out.println("Welcome to OpenCV " + Core.VERSION);
Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
System.out.println("OpenCV Mat: " + m);
Mat mr1 = m.row(1);
mr1.setTo(new Scalar(1));
Mat mc5 = m.col(5);
mc5.setTo(new Scalar(5));
System.out.println("OpenCV Mat data:\n" + m.dump());
>
>

Let me know if you liked it and more importantly, if you know a better way to do this.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *