With each release of OpenCV, new features and various changes are introduced. Also, various bugs are fixed. If the OpenCV code snippet is not working due unavailable function, cause of that problem can be incorrect OpenCV version. This tutorial demonstrates how to get OpenCV version programmatically.
import cv2
version = cv2.__version__
(majorVersion, minorVersion, patchVersion) = cv2.__version__.split('.')
print(version)
print(majorVersion)
print(minorVersion)
print(patchVersion)
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
std::string version = CV_VERSION;
int majorVersion = CV_MAJOR_VERSION;
int minorVersion = CV_MINOR_VERSION;
int patchVersion = CV_SUBMINOR_VERSION;
std::cout << version << std::endl;
std::cout << majorVersion << std::endl;
std::cout << minorVersion << std::endl;
std::cout << patchVersion << std::endl;
return 0;
}
package app;
import org.opencv.core.Core;
public class Main
{
static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
public static void main(String[] args)
{
String version = Core.getVersionString();
int majorVersion = Core.getVersionMajor();
int minorVersion = Core.getVersionMinor();
int patchVersion = Core.getVersionRevision();
System.out.println(version);
System.out.println(majorVersion);
System.out.println(minorVersion);
System.out.println(patchVersion);
System.exit(0);
}
}
Output example:
4.6.0
4
6
0
Leave a Comment
Cancel reply