### setup (filename) Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1Retina.html Attempts to open an XML retina parameters file to adjust the current retina instance setup. If the file does not exist or is invalid, default setup is applied. ```APIDOC ## setup(String retinaParameterFile = "", const bool applyDefaultSetupOnFailure = true) ### Description Try to open an XML retina parameters file to adjust the current retina instance setup. If the XML file does not exist, then default setup is applied. Exceptions are thrown if the read XML file is not valid. ### Method `void cv::bioinspired::Retina::setup(String retinaParameterFile = "", const bool applyDefaultSetupOnFailure = true)` ### Parameters #### Optional Parameters - **retinaParameterFile** (String) - Defaults to "". The parameters filename. You can retrieve the current parameters structure using `Retina::getParameters` and update it before running `Retina::setup`. - **applyDefaultSetupOnFailure** (bool) - Defaults to true. Set to true if an error must be thrown on error. ``` -------------------------------- ### Tiny OpenCV Hello World Source: https://docs.opencv.org/5.0/py_tutorials/py_setup/py_pip_install/py_pip_install.html A minimal example to verify your OpenCV installation. It prints the OpenCV version, creates a simple image with text, and saves it to a file. If a non-headless version is installed, you can optionally display the image in a window. ```python import cv2 as cv import numpy as np print("OpenCV:", cv.__version__) img = np.zeros((120, 400, 3), dtype=np.uint8) cv.putText(img, "OpenCV OK", (10, 80), cv.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), 3) # If you installed a non-headless build, you can display a window: # cv.imshow("hello", img); cv.waitKey(0) # Always safe (headless or not): save to file cv.imwrite("hello.png", img) ``` -------------------------------- ### OpenNI Installation Paths Source: https://docs.opencv.org/5.0/tutorials/app/kinect_openni.html Example paths for installing OpenNI and PrimeSensor Module on Linux, MacOSX, and Windows. Adjust CMake variables if installed in non-default locations. ```text OpenNI: Linux & MacOSX: Libs into: /usr/lib Includes into: /usr/include/ni Windows: Libs into: c:/Program Files/OpenNI/Lib Includes into: c:/Program Files/OpenNI/Include PrimeSensor Module: Linux & MacOSX: Bins into: /usr/bin Windows: Bins into: c:/Program Files/Prime Sense/Sensor/Bin ``` -------------------------------- ### Example Paths for Running Java OpenCV Sample Source: https://docs.opencv.org/5.0/tutorials/introduction/desktop_java/java_dev_intro.html This example provides concrete paths for the 'ocvJarDir' and 'ocvLibDir' properties when running the Ant build command. Adjust these paths to match your OpenCV installation. ```bash ant -DocvJarDir=X:\opencv-2.4.4\bin -DocvLibDir=X:\opencv-2.4.4\bin\Release ``` -------------------------------- ### setup(String segmentationParameterFile = "", const bool applyDefaultSetupOnFailure = true) Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1TransientAreasSegmentationModule.html Attempts to open an XML segmentation parameters file to adjust the current setup. Applies default setup on failure. ```APIDOC ## setup(String segmentationParameterFile = "", const bool applyDefaultSetupOnFailure = true) ### Description Attempts to open an XML segmentation parameters file to adjust the current segmentation instance setup. If the XML file does not exist, the default setup is applied. Warning: Exceptions are thrown if the read XML file is not valid. ### Method `void cv::bioinspired::TransientAreasSegmentationModule::setup(String segmentationParameterFile = "", const bool applyDefaultSetupOnFailure = true)` ### Python Example ```python cv.bioinspired.TransientAreasSegmentationModule.setup([, segmentationParameterFile[, applyDefaultSetupOnFailure]]) ``` ### Parameters * `segmentationParameterFile` (String, optional) - The parameters filename. Defaults to an empty string. * `applyDefaultSetupOnFailure` (bool, optional) - Set to true if an error must be thrown on failure. Defaults to true. ``` -------------------------------- ### Install OpenCV using Ninja Source: https://docs.opencv.org/5.0/tutorials/introduction/linux_install/linux_install.html Alternatively, use the 'ninja install' command with sudo privileges for installation. This is often faster than 'make install'. ```bash sudo ninja install ``` -------------------------------- ### Execute Installation Script (git-bash) Source: https://docs.opencv.org/5.0/tutorials/introduction/windows_install/windows_install.html Run the 'installOCV.sh' script from your git-bash terminal to start the OpenCV build and installation process. ```bash ./installOCV.sh ``` -------------------------------- ### Set Relative Installation Path Source: https://docs.opencv.org/5.0/tutorials/introduction/config_reference/config_reference.html Set the installation path relative to the current working directory. This example sets it to a 'install' subdirectory. ```bash cmake -DCMAKE_INSTALL_PREFIX=install ../opencv ``` -------------------------------- ### setup(FileStorage &fs, const bool applyDefaultSetupOnFailure = true) Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1TransientAreasSegmentationModule.html Attempts to open an XML segmentation parameters file to adjust the current setup. Applies default setup on failure. ```APIDOC ## setup(cv::FileStorage & fs, const bool applyDefaultSetupOnFailure = true) ### Description Attempts to open an XML segmentation parameters file to adjust the current segmentation instance setup. If the XML file does not exist, the default setup is applied. Warning: Exceptions are thrown if the read XML file is not valid. ### Method `void cv::bioinspired::TransientAreasSegmentationModule::setup(cv::FileStorage & fs, const bool applyDefaultSetupOnFailure = true)` ### Parameters * `fs` (cv::FileStorage &) - The open FileStorage object containing segmentation parameters. * `applyDefaultSetupOnFailure` (bool, optional) - Set to true if an error must be thrown on failure. Defaults to true. ``` -------------------------------- ### GrabCut Algorithm C++ Example Source: https://docs.opencv.org/5.0/examples/samples_cpp_grabcut_cpp.html This is the main C++ code for the GrabCut algorithm example. It includes setup, mouse event handling, and the core segmentation logic. Ensure you have OpenCV installed and linked. ```cpp #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" #include using namespace std; using namespace cv; static void help(char** argv) { cout << "\nThis program demonstrates GrabCut segmentation -- select an object in a region\n" "and then grabcut will attempt to segment it out.\n" "Call:\n" << argv[0] << " \n" "\nSelect a rectangular area around the object you want to segment\n" << "\nHot keys: \n" "\tESC - quit the program\n" ``` ```cpp r - restore the original image\n" ``` ```cpp n - next iteration\n" ``` ```cpp "\n" ``` ```cpp "\tleft mouse button - set rectangle\n" ``` ```cpp "\n" ``` ```cpp "\tCTRL+left mouse button - set GC_BGD pixels\n" ``` ```cpp "\tSHIFT+left mouse button - set GC_FGD pixels\n" ``` ```cpp "\n" ``` ```cpp "\tCTRL+right mouse button - set GC_PR_BGD pixels\n" ``` ```cpp "\tSHIFT+right mouse button - set GC_PR_FGD pixels\n" << endl; ``` ```cpp } const Scalar RED = Scalar(0,0,255); const Scalar PINK = Scalar(230,130,255); const Scalar BLUE = Scalar(255,0,0); const Scalar LIGHTBLUE = Scalar(255,255,160); const Scalar GREEN = Scalar(0,255,0); const int BGD_KEY = EVENT_FLAG_CTRLKEY; const int FGD_KEY = EVENT_FLAG_SHIFTKEY; static void getBinMask( const Mat& comMask, Mat& binMask ) { if( comMask.empty() || comMask.type()!=CV_8UC1 ) CV_Error( Error::StsBadArg, "comMask is empty or has incorrect type (not CV_8UC1)" ); if( binMask.empty() || binMask.rows!=comMask.rows || binMask.cols!=comMask.cols ) binMask.create( comMask.size(), CV_8UC1 ); binMask = comMask & 1; } class GCApplication { public: enum{ NOT_SET = 0, IN_PROCESS = 1, SET = 2 }; static const int radius = 2; static const int thickness = -1; void reset(); void setImageAndWinName( const Mat& _image, const string& _winName ); void showImage() const; void mouseClick( int event, int x, int y, int flags, void* param ); int nextIter(); int getIterCount() const { return iterCount; } private: void setRectInMask(); void setLblsInMask( int flags, Point p, bool isPr ); const string* winName; const Mat* image; Mat mask; Mat bgdModel, fgdModel; uchar rectState, lblsState, prLblsState; bool isInitialized; Rect rect; vector fgdPxls, bgdPxls, prFgdPxls, prBgdPxls; int iterCount; }; void GCApplication::reset() { if( !mask.empty() ) mask.setTo(Scalar::all(GC_BGD)); bgdPxls.clear(); fgdPxls.clear(); prBgdPxls.clear(); prFgdPxls.clear(); isInitialized = false; rectState = NOT_SET; lblsState = NOT_SET; prLblsState = NOT_SET; iterCount = 0; } void GCApplication::setImageAndWinName( const Mat& _image, const string& _winName ) { if( _image.empty() || _winName.empty() ) return; image = &_image; winName = &_winName; mask.create( image->size(), CV_8UC1); reset(); } void GCApplication::showImage() const { if( image->empty() || winName->empty() ) return; Mat res; Mat binMask; image->copyTo( res ); if( isInitialized ){ getBinMask( mask, binMask); Mat black (binMask.rows, binMask.cols, CV_8UC3, cv::Scalar(0,0,0)); black.setTo(Scalar::all(255), binMask); addWeighted(black, 0.5, res, 0.5, 0.0, res); } vector::const_iterator it; for( it = bgdPxls.begin(); it != bgdPxls.end(); ++it ) circle( res, *it, radius, BLUE, thickness ); for( it = fgdPxls.begin(); it != fgdPxls.end(); ++it ) circle( res, *it, radius, RED, thickness ); for( it = prBgdPxls.begin(); it != prBgdPxls.end(); ++it ) circle( res, *it, radius, LIGHTBLUE, thickness ); for( it = prFgdPxls.begin(); it != prFgdPxls.end(); ++it ) circle( res, *it, radius, PINK, thickness ); if( rectState == IN_PROCESS || rectState == SET ) rectangle( res, Point( rect.x, rect.y ), Point(rect.x + rect.width, rect.y + rect.height ), GREEN, 2); imshow( *winName, res ); } void GCApplication::setRectInMask() { CV_Assert( !mask.empty() ); mask.setTo( GC_BGD ); rect.x = max(0, rect.x); rect.y = max(0, rect.y); rect.width = min(rect.width, image->cols-rect.x); rect.height = min(rect.height, image->rows-rect.y); (mask(rect)).setTo( Scalar(GC_PR_FGD) ); } ``` -------------------------------- ### Install OpenCV on Mac OS X (Quick Start) Source: https://docs.opencv.org/5.0/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.html A minimal guide to installing OpenCV on Mac OS X, assuming Xcode, JDK, and CMake are already installed. This involves cloning the repository, checking out a specific version, building with CMake, and optionally installing. ```bash cd ~/ mkdir opt git clone https://github.com/opencv/opencv.git cd opencv git checkout 2.4 mkdir build cd build cmake -DBUILD_SHARED_LIBS=OFF .. ... ... make -j8 ## optional ## make install ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://docs.opencv.org/5.0/py_tutorials/py_setup/py_pip_install/py_pip_install.html Before installing packages, it's recommended to create and activate a virtual environment to isolate project dependencies. This example shows how to create a `.venv` directory and activate it on Windows and Linux/macOS. ```bash python -m venv .venv # Windows: .venv\Scripts\activate # Linux/macOS: source .venv/bin/activate ``` -------------------------------- ### C++ Example: main.cpp Source: https://docs.opencv.org/5.0/tutorials/introduction/windows_msys2_vscode/window_install_opencv.html A simple C++ program to verify the OpenCV installation by printing the version and displaying a blank image. ```cpp #include #include int main() { std::cout << "OpenCV Version: " << CV_VERSION << std::endl; cv::Mat img = cv::Mat::zeros(400, 400, CV_8UC3); cv::imshow("OpenCV Test", img); cv::waitKey(0); return 0; } ``` -------------------------------- ### setup (FileStorage) Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1Retina.html Sets up the retina instance using parameters from an open FileStorage. Allows for default setup on failure. ```APIDOC ## setup(FileStorage & fs, const bool applyDefaultSetupOnFailure = true) ### Description Sets up the retina instance using parameters from an open FileStorage. If `applyDefaultSetupOnFailure` is true, a default setup is applied if an error occurs. ### Method `void cv::bioinspired::Retina::setup(cv::FileStorage & fs, const bool applyDefaultSetupOnFailure = true)` ### Parameters #### Input Parameters - **fs** (cv::FileStorage&) - The open FileStorage which contains retina parameters. #### Optional Parameters - **applyDefaultSetupOnFailure** (bool) - Defaults to true. Set to true if an error must be thrown on error. ``` -------------------------------- ### Execute Node.js Script Source: https://docs.opencv.org/5.0/js_tutorials/js_setup/js_nodejs/js_nodejs.html Command to run the Node.js example file. Ensure opencv.js is in the same directory and Node.js is installed. ```bash node example1.js ``` -------------------------------- ### Install Built Library Files Source: https://docs.opencv.org/5.0/tutorials/introduction/config_reference/config_reference.html After building the library, use this command to copy all files to the configured installation location. ```bash cmake --build . --target install ``` -------------------------------- ### Build and Install OpenCV Artifacts Source: https://docs.opencv.org/5.0/tutorials/introduction/crosscompilation/crosscompile_with_multiarch.html After configuration, use these commands to build the OpenCV project and install the artifacts into a designated 'install' folder on the host system. ```bash cmake --build build4-full_arm64 ``` ```bash sudo cmake --install build4-full_arm64 ``` -------------------------------- ### Build and Install OpenCV Source: https://docs.opencv.org/5.0/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.html Compiles the OpenCV library using 'make' and installs it to the system using 'make install'. ```bash $ make # sudo make install ``` -------------------------------- ### Install Project with CMake Source: https://docs.opencv.org/5.0/tutorials/introduction/general_install/general_install.html Install the built project files to the specified location. This step copies build results and other files from the build directory to the install prefix. Administrator privileges may be required for protected system directories. ```bash cmake --build --target install ``` -------------------------------- ### Start REPL Source: https://docs.opencv.org/5.0/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.html Command to start the Clojure REPL with Leiningen. ```bash lein repl ``` -------------------------------- ### Command Line Arguments for Sample Source: https://docs.opencv.org/5.0/tutorials/objdetect/aruco_detection/aruco_detection.html Example of how to pass parameters to the sample application via the command line. This includes specifying the input image, dictionary, and camera calibration file. ```bash -v=/path_to_opencv/opencv/doc/tutorials/objdetect/aruco_detection/images/singlemarkersoriginal.jpg -d=10 -c=/path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/tutorial_camera_params.yml ``` -------------------------------- ### Run Retina Tutorial Source: https://docs.opencv.org/5.0/tutorials_contrib/bioinspired/retina_model/retina_model.html Examples of how to run the compiled retina_tutorial executable with different media inputs and sampling options. ```bash ./Retina_tuto -video // run on video file ./Retina_tuto -video myVideo.avi // run on an image ./Retina_tuto -image myPicture.jpg // run on an image with log sampling ./Retina_tuto -image myPicture.jpg log ``` -------------------------------- ### Print Retina Setup Configuration Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1Retina.html Outputs a string showing the current parameters setup for the retina module. ```python cv.bioinspired.Retina.printSetup() -> retval ``` -------------------------------- ### setUp() Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1videostab_1_1TwoPassStabilizer.html Sets up the TwoPassStabilizer with the first frame. ```APIDOC ## setUp(const Mat & firstFrame) ### Description Initializes the TwoPassStabilizer with the first frame of the video sequence. ### Method `void cv::videostab::TwoPassStabilizer::setUp(const Mat & firstFrame)` ### Parameters - **firstFrame** (const Mat &) - Required - The first frame of the video sequence. ``` -------------------------------- ### Get Start Point of KeyLine Source: https://docs.opencv.org/5.0/extra_modules/structcv_1_1line__descriptor_1_1KeyLine.html Retrieves the start point coordinates of the line in the original image. Use this to get the absolute position of the line's start. ```python cv.line_descriptor.KeyLine.getStartPoint() ``` -------------------------------- ### Install Make Build System Source: https://docs.opencv.org/5.0/tutorials/introduction/linux_install/linux_install.html Installs the Make utility, a common build automation tool, on Debian/Ubuntu-based systems. ```bash sudo apt install -y make ``` -------------------------------- ### Install Valgrind and Massif Visualizer Source: https://docs.opencv.org/5.0/tutorials_contrib/gapi/anisotropic_segmentation/porting_anisotropic_segmentation.html Install necessary profiling tools on Debian/Ubuntu systems. Requires administrator privileges. ```bash $ sudo apt-get install valgrind massif-visualizer ``` -------------------------------- ### Verify OpenCV-Python Installation Source: https://docs.opencv.org/5.0/py_tutorials/py_setup/py_setup_in_ubuntu/py_setup_in_ubuntu.html After installation, import the cv2 library in Python and print its version to confirm successful setup. This can be done in the Python IDLE or IPython terminal. ```python import cv2 as cv print(cv.__version__) ``` -------------------------------- ### setUp() Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1videostab_1_1OnePassStabilizer.html Sets up the stabilizer with the first frame (protected member). ```APIDOC ## setUp(const Mat & firstFrame) ### Description Protected method to set up the stabilizer using the first frame of the sequence. ### Parameters * **firstFrame** (`const Mat &`) - The first frame of the video sequence. ### Method Signature `void cv::videostab::OnePassStabilizer::setUp(const Mat & firstFrame)` ``` -------------------------------- ### Running PnP Detection with Custom Parameters Source: https://docs.opencv.org/5.0/tutorials/calib3d/real_time_pose/real_time_pose.html This command-line example shows how to execute the PnP detection tutorial with custom parameters for the ratio test threshold, number of keypoints, and fast detection. ```bash ./cpp-tutorial-pnp_detection --ratio=0.8 --keypoints=1000 --fast=false ``` -------------------------------- ### Get Row Range Header (Start and End Rows) Source: https://docs.opencv.org/5.0/main_modules/classcv_1_1UMat.html Returns a new matrix header for a specified span of rows using start and end row indices. ```C++ UMat cv::UMat::rowRange( int startrow, int endrow ) ``` -------------------------------- ### Get Start Point in Octave Source: https://docs.opencv.org/5.0/extra_modules/structcv_1_1line__descriptor_1_1KeyLine.html Retrieves the start point coordinates of the line in the specific octave it was extracted from. This is useful for understanding the line's representation at different pyramid levels. ```python cv.line_descriptor.KeyLine.getStartPointInOctave() ``` -------------------------------- ### printSetup Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1TransientAreasSegmentationModule.html Displays the current parameter setup information as a formatted string. ```APIDOC ## printSetup() ### Description Prints the current parameter setup. ### Method `String cv::bioinspired::TransientAreasSegmentationModule::printSetup()` ### Python Example ```python retval = cv.bioinspired.TransientAreasSegmentationModule.printSetup() ``` ### Returns A string containing formatted parameters information. ``` -------------------------------- ### Get Library Version Revision Source: https://docs.opencv.org/5.0/main_modules/utility_8hpp.html Retrieves the revision number of the installed OpenCV library. ```cpp int cv::getVersionRevision () ``` -------------------------------- ### printSetup Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1Retina.html Outputs a string containing the current parameters setup of the retina instance. ```APIDOC ## printSetup() ### Description Outputs a string showing the used parameters setup for the retina instance. ### Method `String cv::bioinspired::Retina::printSetup()` ### Returns - `String` - A string containing formatted parameters information. ``` -------------------------------- ### Get First Level (Python) Source: https://docs.opencv.org/5.0/main_modules/classcv_1_1ORB.html Retrieves the starting pyramid level for image processing. ```python cv.ORB.getFirstLevel() -> retval ``` -------------------------------- ### cv::cuda::ORB::getFirstLevel Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1cuda_1_1ORB.html Gets the level of the pyramid where keypoint detection is started. ```APIDOC ## cv::cuda::ORB::getFirstLevel ### Description Gets the level of the pyramid where keypoint detection is started. ### Signature `int cv::cuda::ORB::getFirstLevel()` ``` -------------------------------- ### setup (RetinaParameters) Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1Retina.html Sets up the retina instance with a new set of parameters. ```APIDOC ## setup(RetinaParameters newParameters) ### Description Sets up the retina instance with a new set of parameters provided in a `RetinaParameters` structure. ### Method `void cv::bioinspired::Retina::setup(RetinaParameters newParameters)` ### Parameters #### Input Parameters - **newParameters** (RetinaParameters) - A parameters structure updated with the new target configuration. ``` -------------------------------- ### Install Core OpenCV Modules on Linux Source: https://docs.opencv.org/5.0/tutorials/introduction/linux_install/linux_install.html Installs essential prerequisites, downloads, and builds the core OpenCV modules using CMake and Ninja. This is a minimal setup for basic OpenCV functionality. ```bash # Install minimal prerequisites (Ubuntu 18.04 as reference) sudo apt update && sudo apt install -y cmake g++ wget unzip ninja-build # Download and unpack sources wget -O opencv.zip https://github.com/opencv/opencv/archive/5.x.zip unzip opencv.zip # Create build directory mkdir -p build && cd build # Configure cmake -GNinja ../opencv-5.x # Build cmake --build . ``` -------------------------------- ### help_init Source: https://docs.opencv.org/5.0/extra_modules/structcv_1_1detail_1_1scratch__helper_3_01true_00_01Impl_00_01Ins_8_8_8_01_4.html Initializes the scratch buffer with provided metadata and input arguments. ```APIDOC ## Static Public Member Functions Return | Name | Description ---|---|--- `static void` | `help_init(` ` const cv::GMetaArgs & metas,` ` const cv::GArgs & in_args,` ` gapi::fluid::Buffer & b )` | ### help_init() `static void cv::detail::scratch_helper< true, Impl, Ins… >::help_init(` ` const cv::GMetaArgs & metas,` ` const cv::GArgs & in_args,` ` gapi::fluid::Buffer & b )` ``` -------------------------------- ### cv::detail::OCVSetupHelper::setup Source: https://docs.opencv.org/5.0/extra_modules/structcv_1_1detail_1_1OCVSetupHelper_3_01Impl_00_01std_1_1tuple_3_01Ins_8_8_8_01_4_01_4.html The static `setup` method is the primary interface for configuring the kernel state. It takes metadata, arguments, the state object, and compilation arguments to prepare the kernel for execution. ```APIDOC ## cv::detail::OCVSetupHelper::setup ### Description This static method is used to set up the kernel's state. It takes metadata, arguments, a state object, and compilation arguments. ### Method `static void` ### Parameters - **metaArgs** (const GMetaArgs &) - Metadata arguments for the kernel. - **args** (const GArgs &) - Arguments for the kernel. - **state** (GArg &) - The state object to be configured. - **compileArgs** (const GCompileArgs &) - Compilation arguments. ``` -------------------------------- ### Create a new MultiTracker instance Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1legacy_1_1MultiTracker.html Instantiates a new MultiTracker object. This is the primary way to get started with the MultiTracker. ```Python cv.legacy.MultiTracker() ``` -------------------------------- ### Initialize and Display GUI Window Source: https://docs.opencv.org/5.0/tutorials/imgproc/shapedescriptors/moments/moments.html Sets up the main window, loads the image, and adds UI components like sliders and image panels. It converts the source image to a buffered image for display. ```java /// Convert image to gray and blur it Imgproc.cvtColor(src, srcGray, Imgproc.COLOR_BGR2GRAY); Imgproc.blur(srcGray, srcGray, new Size(3, 3)); // Create and set up the window. frame = new JFrame("Image Moments demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the content pane. Image img = HighGui.toBufferedImage(src); addComponentsToPane(frame.getContentPane(), img); // Use the content pane's default BorderLayout. No need for // setLayout(new BorderLayout()); // Display the window. frame.pack(); frame.setVisible(true); update(); ``` -------------------------------- ### Get Retina Parameters Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1Retina.html Retrieves the current parameter setup of the Retina object. This allows inspection of the active configuration. ```Python cv.bioinspired.Retina.getParameters() ``` -------------------------------- ### ChArUco Board Sample Command Line Arguments Source: https://docs.opencv.org/5.0/tutorials/objdetect/charuco_detection/charuco_detection.html Example command-line arguments for the `create_board_charuco.cpp` sample application. These arguments define the output path, board dimensions, square and marker lengths, and dictionary. ```bash "_output_path_/chboard.png" -w=5 -h=7 -sl=100 -ml=60 -d=10 ``` -------------------------------- ### Example: Running Pose Detection with P3P Method Source: https://docs.opencv.org/5.0/tutorials/calib3d/real_time_pose/real_time_pose.html This example demonstrates how to execute the pose detection application with a specific PnP method, in this case, P3P (method index 2). This is useful for testing different pose estimation algorithms. ```bash ./cpp-tutorial-pnp_detection --method=2 ``` -------------------------------- ### Complete Viz Window Launching Example Source: https://docs.opencv.org/5.0/tutorials_contrib/viz/launching_viz/launching_viz.html This is a comprehensive example demonstrating how to create, display, and interact with a viz window. It shows how to start a continuous event loop, access the window by name, and run a controlled event loop for a specified duration. ```C++ #include #include using namespace cv; using namespace std; static void help() { cout << "--------------------------------------------------------------------------" << endl << "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. " << "You can access the same window via its name. You can run event loop for a given period of time. " << endl << "Usage:" << endl << "./launching_viz" << endl << endl; } int main() { help(); /// Create a window viz::Viz3d myWindow("Viz Demo"); /// Start event loop myWindow.spin(); /// Event loop is over when pressed q, Q, e, E cout << "First event loop is over" << endl; /// Access window via its name viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo"); /// Start event loop sameWindow.spin(); /// Event loop is over when pressed q, Q, e, E cout << "Second event loop is over" << endl; /// Event loop is over when pressed q, Q, e, E /// Start event loop once for 1 millisecond sameWindow.spinOnce(1, true); while(!sameWindow.wasStopped()) { /// Interact with window /// Event loop for 1 millisecond sameWindow.spinOnce(1, true); } /// Once more event loop is stopped cout << "Last event loop is over" << endl; return 0; } ``` -------------------------------- ### start() Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1GStreamingCompiled.html Starts the pipeline execution. Use pull()/try_pull() to obtain data. Throws an exception if a video source was not specified. setSource() must be called first, even if the pipeline has been working already and then stopped. ```APIDOC ## start() ### Description Start the pipeline execution. Use pull()/try_pull() to obtain data. Throws an exception if a video source was not specified. setSource() must be called first, even if the pipeline has been working already and then stopped (explicitly via stop() or due stream completion). Note This method is not thread-safe (with respect to the user side) at the moment. Protect the access if start()/stop()/setSource() may be called on the same object in multiple threads in your application. ``` -------------------------------- ### Troubleshooting: CMake cannot find OpenCV Source: https://docs.opencv.org/5.0/tutorials/introduction/windows_msys2_vscode/window_install_opencv.html Example of how to set the OpenCV_DIR variable in CMakeLists.txt to help CMake locate the installed OpenCV libraries. ```cmake set(OpenCV_DIR "C:/path/to/opencv/build/install/lib/cmake/opencv4") ``` -------------------------------- ### Serve Build Directory with http-server Source: https://docs.opencv.org/5.0/js_tutorials/js_setup/js_setup/js_setup.html Starts a local web server in the specified build directory to serve test files. Navigate to tests.html in your browser to run tests. ```bash npx http-server build_js/bin firefox http://localhost:8080/tests.html ``` -------------------------------- ### iOS ViewController Interface Setup Source: https://docs.opencv.org/5.0/tutorials/ios/video_processing/video_processing.html Defines the basic Objective-C interface for a ViewController, including outlets for an ImageView and a Button, and an action for starting the camera. ```objectivec @interface ViewController : UIViewController { IBOutlet UIImageView* imageView; IBOutlet UIButton* button; } - (IBAction)actionStart:(id)sender; @end ``` -------------------------------- ### Run Example from Command Line Source: https://docs.opencv.org/5.0/tutorials/dnn/dnn_googlenet/dnn_googlenet.html Executes the classification example using the GoogLeNet model. The output typically shows a prediction like 'space shuttle' with high confidence. ```bash ./example_dnn_classification googlenet ``` -------------------------------- ### Get Tick Count for Timing Source: https://docs.opencv.org/5.0/main_modules/utility_8hpp.html Returns the number of ticks since some arbitrary starting point. Used in conjunction with getTickFrequency for precise timing. ```cpp int64 cv::getTickCount () ``` -------------------------------- ### Running Executable with Arguments in Command Prompt Source: https://docs.opencv.org/5.0/tutorials/introduction/windows_visual_studio_opencv/windows_visual_studio_opencv.html This example shows how to navigate to your project's executable directory in the command prompt and run it with a sample argument. ```bash D: CD OpenCV\MySolutionName\Release MySolutionName.exe exampleImage.jpg ``` -------------------------------- ### Python: Super Resolution Upscaling Workflow Source: https://docs.opencv.org/5.0/tutorials_contrib/dnn_superres/upscale_image_single/upscale_image_single.html A complete example in Python demonstrating image loading, model setup, upscaling, and saving the result. Uses the `dnn_superres` module. ```python import cv2 from cv2 import dnn_superres ## Create an SR object - only function that differs from c++ code sr = dnn_superres.DnnSuperResImpl_create() ## Read image image = cv2.imread('./image.png') ## Read the desired model path = "EDSR_x4.pb" sr.readModel(path) ## Set the desired model and scale to get correct pre- and post-processing sr.setModel("edsr", 4) ## Upscale the image result = sr.upsample(image) ## Save the image cv2.imwrite("./upscaled.png", result) ``` -------------------------------- ### Install GUI and Media Support Dependencies Source: https://docs.opencv.org/5.0/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.html Installs GTK for GUI features, libdc1394 for camera support, and ffmpeg/gstreamer for media processing. ```bash yum install gtk2-devel yum install libdc1394-devel yum install ffmpeg-devel yum install gstreamer-plugins-base-devel ``` -------------------------------- ### Set and Get Sensor Properties Source: https://docs.opencv.org/5.0/tutorials/app/intelperc.html Use VideoCapture::set and VideoCapture::get to configure and query sensor properties. This example sets the profile index and retrieves the FPS. ```cpp VideoCapture capture(CAP_REALSENSE); capture.set( CAP_INTELPERC_DEPTH_GENERATOR | CAP_PROP_INTELPERC_PROFILE_IDX, 0 ); cout << "FPS " << capture.get( CAP_INTELPERC_DEPTH_GENERATOR+CAP_PROP_FPS ) << endl; ``` -------------------------------- ### Minimal Node.js Example for OpenCV.js Source: https://docs.opencv.org/5.0/js_tutorials/js_setup/js_nodejs/js_nodejs.html This snippet demonstrates the basic setup for running OpenCV.js in Node.js. It defines the Module.onRuntimeInitialized callback and loads the opencv.js library using require. ```javascript // Define a global variable 'Module' with a method 'onRuntimeInitialized': Module = { onRuntimeInitialized() { // this is our application: console.log(cv.getBuildInformation()) } } // Load 'opencv.js' assigning the value to the global variable 'cv' cv = require('./opencv.js') ``` -------------------------------- ### Initialize Window and Trackbar (Python) Source: https://docs.opencv.org/5.0/tutorials/imgproc/histograms/back_projection/back_projection.html Sets up the display window and a trackbar for adjusting histogram bins in Python. ```Python window_image = 'Source image' cv.namedWindow(window_image) bins = 25 cv.createTrackbar('* Hue bins: ', window_image, bins, 180, Hist_and_Backproj ) Hist_and_Backproj(bins) ``` -------------------------------- ### Planar Tracking Command Line Source: https://docs.opencv.org/5.0/tutorials/features/akaze_tracking/akaze_tracking.html Example command to run the planar tracking application with a video file. Ensure you have the OpenCV contrib module 'xfeatures2d' installed for AKAZE features. ```bash ./planar_tracking blais.mp4 ``` -------------------------------- ### Set up Project Directory and Dependencies Source: https://docs.opencv.org/5.0/tutorials/introduction/desktop_java/java_dev_intro.html Create the necessary directories and copy the OpenCV JAR file into the lib folder. This step ensures SBT can find and include the OpenCV library in your project. ```bash mkdir lib cp /build/bin/opencv_.jar lib/ sbt eclipse ``` -------------------------------- ### Set Up Intel oneAPI Environment Source: https://docs.opencv.org/5.0/tutorials/introduction/oneapi_install/oneapi_install.html Load the oneAPI environment variables to make compilers and libraries available in your shell. This is for a default installation path. ```bash source /opt/intel/oneapi/setvars.sh ``` -------------------------------- ### OpenCV DNN Text Detection and Recognition Setup Source: https://docs.opencv.org/5.0/examples/samples_dnn_text_detection_cpp.html This C++ code sets up the command-line argument parser for the text detection and recognition example. It defines keys for input, models, and various detection/recognition parameters. ```cpp #include #include #include #include #include #include #include "common.hpp" using namespace cv; using namespace std; using namespace cv::dnn; const string about = "Use this script for Text Detection and Recognition using OpenCV. \n\n" "Firstly, download required models using `download_models.py` (if not already done). Set environment variable OPENCV_DOWNLOAD_CACHE_DIR to point to the directory where models are downloaded. Also, point OPENCV_SAMPLES_DATA_PATH to opencv/samples/data.\n" "To run:\n" "\t Example: ./example_dnn_text_detection modelName(i.e. DB or East) --ocr_model=\n\n" "Detection model path can also be specified using --model argument. \n\n" "Download ocr model using: python download_models.py OCR \n\n"; // Command-line keys to parse the input arguments string keys = "{ help h | | Print help message. }" "{ input i | right.jpg | Path to an input image. }" "{ @alias | | An alias name of model to extract preprocessing parameters from models.yml file. }" "{ zoo | ../dnn/models.yml | An optional path to file with preprocessing parameters }" "{ ocr_model | | Path to a binary .onnx model for recognition. }" "{ model | | Path to detection model file. }" "{ thr | 0.5 | Confidence threshold for EAST detector. }" "{ nms | 0.4 | Non-maximum suppression threshold for EAST detector. }" "{ binaryThreshold bt | 0.3 | Confidence threshold for the binary map in DB detector. }" "{ polygonThreshold pt | 0.5 | Confidence threshold for polygons in DB detector. }" "{ maxCandidate max | 200 | Max candidates for polygons in DB detector. }" "{ unclipRatio ratio | 2.0 | Unclip ratio for DB detector. }" "{ vocabularyPath vp | alphabet_36.txt | Path to vocabulary file. }"; // Function prototype for the four-point perspective transform static void fourPointsTransform(const Mat& frame, const Point2f vertices[], Mat& result); static void processFrame( const Mat& frame, const vector>& detResults, const std::string& ocr_model, bool imreadRGB, Mat& board, FontFace& fontFace, int fontSize, int fontWeight, const vector& vocabulary ); int main(int argc, char** argv) { // Setting up command-line parser with the specified keys CommandLineParser parser(argc, argv, keys); if (!parser.has("@alias") || parser.has("help")) { cout << about << endl; parser.printMessage(); return -1; } const string modelName = parser.get("@alias"); const string zooFile = findFile(parser.get("zoo")); keys += genPreprocArguments(modelName, zooFile, ""); keys += genPreprocArguments(modelName, zooFile, "ocr_"); parser = CommandLineParser(argc, argv, keys); parser.about(about); // Parsing command-line arguments ``` -------------------------------- ### Get Maximum Input Image Value for LearningBasedWB Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1xphoto_1_1LearningBasedWB.html Retrieves the maximum possible value for input image pixels, used in saturation threshold calculations. For example, 255 for 8-bit images or 4095 for 12-bit images. ```Python cv.xphoto.LearningBasedWB.getRangeMaxVal() -> retval ``` -------------------------------- ### start() Source: https://docs.opencv.org/5.0/main_modules/classcv_1_1GStreamingCompiled.html Starts the pipeline execution. Use pull()/try_pull() to obtain data. Throws an exception if a video source was not specified. setSource() must be called first, even if the pipeline was previously stopped. ```APIDOC ## start() ### Description Start the pipeline execution. ### Throws Throws an exception if a video source was not specified. ### Note This method is not thread-safe (with respect to the user side) at the moment. Protect the access if start()/stop()/setSource() may be called on the same object in multiple threads in your application. ### Usage Use pull()/try_pull() to obtain data. setSource() must be called first, even if the pipeline has been working already and then stopped (explicitly via stop() or due stream completion). ``` -------------------------------- ### Print All CMake Options Source: https://docs.opencv.org/5.0/tutorials/introduction/config_reference/config_reference.html Use CMake to list all available configuration options. Use -L to list all, -LH for options with help messages, and -LA for advanced options. ```bash cmake ../opencv cmake -L cmake -LH cmake -LA ``` -------------------------------- ### Set Image Generator Output Mode and Get FPS Source: https://docs.opencv.org/5.0/tutorials/app/kinect_openni.html Example of setting the image generator output mode to VGA 30Hz and retrieving the frames per second (FPS) using VideoCapture::set and VideoCapture::get. ```cpp VideoCapture capture( CAP_OPENNI2 ); capture.set( CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CAP_OPENNI_VGA_30HZ ); cout << "FPS " << capture.get( CAP_OPENNI_IMAGE_GENERATOR+CAP_PROP_FPS ) << endl; ``` -------------------------------- ### Run DNN Super Resolution Example Source: https://docs.opencv.org/5.0/tutorials_contrib/dnn_superres/upscale_image_single/upscale_image_single.html Execute the dnn_superres example binary with image path, algorithm, scale factor, and model path as arguments. ```bash /bin/example_dnn_superres_dnn_superres ``` ```bash /home/opencv/build/bin/example_dnn_superres_dnn_superres /home/image.png edsr 2 /home/EDSR_x2.pb ``` -------------------------------- ### Minimal Python Example for Chromatic Aberration Correction Source: https://docs.opencv.org/5.0/py_tutorials/py_photo/py_chromatic_aberration/py_chromatic_aberration.html This Python script demonstrates the minimal setup for correcting chromatic aberration using OpenCV. It loads calibration parameters from a YAML file and applies the correction to an input image, optionally displaying the original and corrected images. ```python import cv2 as cv INPUT = "path/to/input.jpg" CALIB_YAML = "path/to/ca_photo_calib.yaml" OUTPUT = "corrected.png" BAYER = -1 SHOW = True FileStorage fs(parsed_args.coeffs_file, FileStorage::READ); coeffMat, calib_size, degree = cv2.loadChromaticAberrationParams(fs.root()) corrected = cv.correctChromaticAberration(img, coeffMat, calib_size, degree, BAYER) if SHOW: cv.namedWindow("Original", cv.WINDOW_AUTOSIZE) cv.namedWindow("Corrected", cv.WINDOW_AUTOSIZE) cv.imshow("Original", img) cv.imshow("Corrected", corrected) print("Press any key to close...") cv.waitKey(0) cv.destroyAllWindows() cv.imwrite(OUTPUT, corrected) ``` -------------------------------- ### Command Line Parser Setup Source: https://docs.opencv.org/5.0/examples/samples_cpp_tutorial_code_features_homography_pose_from_homography_cpp.html Defines command-line parameters for the homography pose estimation sample, including image paths, camera intrinsics, and chessboard properties. ```C++ String keys = "{ h help | | print usage }" "{ image | left04.jpg | path to a chessboard image }" "{ intrinsics | left_intrinsics.yml | path to camera intrinsics }" "{ width bw | 9 | chessboard width }" "{ height bh | 6 | chessboard height }" "{ square_size | 0.025 | chessboard square size }"; ``` -------------------------------- ### Build OpenCV Core Plugin with TBB Source: https://docs.opencv.org/5.0/tutorials/introduction/general_install/general_install.html This example demonstrates how to build the OpenCV core plugin using the Intel Threading Building Blocks (TBB) library. Ensure TBB is installed and its configuration is accessible. Set the OPENCV_PLUGIN_NAME to specify the plugin and OPENCV_PLUGIN_DESTINATION for the output folder. The path to the TBB plugin source is provided as the last argument to cmake. ```bash # set-up environment for TBB detection, for example: # export TBB_DIR= cmake -G \ -DOPENCV_PLUGIN_NAME=opencv_core_tbb_ \ -DOPENCV_PLUGIN_DESTINATION= \ -DCMAKE_BUILD_TYPE= \ /modules/core/misc/plugins/parallel_tbb cmake --build . --config ``` -------------------------------- ### Create Project Structure Source: https://docs.opencv.org/5.0/tutorials/introduction/desktop_java/java_dev_intro.html Set up the necessary folders for an SBT project, including the source directory and project definition directory. ```bash cd JavaSample mkdir -p src/main/java mkdir project ``` -------------------------------- ### Verify MSYS2 Toolchain Installation Source: https://docs.opencv.org/5.0/tutorials/introduction/windows_msys2_vscode/window_install_opencv.html Checks the installed versions of GCC, CMake, and mingw32-make to confirm successful installation. ```bash gcc --version cmake --version mingw32-make --version ``` -------------------------------- ### Example File Format for Camera Images Source: https://docs.opencv.org/5.0/tutorials/calib3d/camera_multiview_calibration/multiview_calibration.html This is an example of how to format a text file listing image paths for a specific camera. Each line should contain a relative path to an image for that camera. ```text /path/to/image_1_of_camera_i /path/to/image_3_of_camera_i ... /path/to/image_M_of_camera_i ``` -------------------------------- ### Install OpenCV Source: https://docs.opencv.org/5.0/tutorials/introduction/building_tegra_cuda/building_tegra_cuda.html Use this command to install OpenCV on Linux-based platforms. Root privileges may be required depending on the installation directory. ```bash $ make install ``` -------------------------------- ### Run Panorama Mode Example Source: https://docs.opencv.org/5.0/tutorials/others/stitcher.html Execute the stitching example in panorama mode with sample data. This requires the `opencv_extra` repository to be available. ```bash ./cpp-example-stitching --mode panorama /testdata/stitching/boat* ``` -------------------------------- ### Create and Configure Display Window (Java) Source: https://docs.opencv.org/5.0/tutorials/imgproc/threshold_inRange/threshold_inRange.html Sets up a JFrame to display the video frames. Includes a window listener to cancel the capture task when the window is closed. ```Java // Create and set up the window. frame = new JFrame(WINDOW_NAME); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { captureTask.cancel(true); } }); // Set up the content pane. Image img = HighGui.toBufferedImage(matFrame); addComponentsToPane(frame.getContentPane(), img); // Use the content pane's default BorderLayout. No need for // setLayout(new BorderLayout()); // Display the window. frame.pack(); frame.setVisible(true); ``` -------------------------------- ### Install OpenCV via Pip Source: https://docs.opencv.org/5.0/tutorials/introduction/macos_install/macos_install.html Install a stable release of OpenCV using pip. This command installs the main OpenCV package. ```bash pip install opencv-python ``` -------------------------------- ### Install to System Location with Elevated Privileges Source: https://docs.opencv.org/5.0/tutorials/introduction/config_reference/config_reference.html To install binaries to a system location like /usr/local as a regular user, run the install command with sudo. ```bash sudo cmake --build . --target install ``` -------------------------------- ### setup(SegmentationParameters newParameters) Source: https://docs.opencv.org/5.0/extra_modules/classcv_1_1bioinspired_1_1TransientAreasSegmentationModule.html Attempts to set up the module using provided SegmentationParameters. ```APIDOC ## setup(SegmentationParameters newParameters) ### Description Attempts to set up the module using provided SegmentationParameters. ### Method `void cv::bioinspired::TransientAreasSegmentationModule::setup(SegmentationParameters newParameters)` ### Parameters * `newParameters` (SegmentationParameters) - A parameters structure updated with the new target configuration. ```