OpenCV Tips

来源:互联网 发布:反ip域名查询 编辑:程序博客网 时间:2024/06/13 11:43

Adding Matrices without saturation

Mat A(10, 10, CV_8UC1, 200);Mat B(10, 10, CV_8UC1, 200);Mat C(10, 10, CV_32S, 0);cv::add(A, B, C);

if you don't specify the dtype arg in cv::add() the 3rd arg will get reallocated to the type(and size) of the input operands, and your initialization of C will get completely ignored.if you check C.type() after the add(A,B,C) you'll find, that it's type is CV_8UC1, not CV_32S.

Operations on Arrays

The input arrays and the output array can all have the same or different depths. For example, you can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit floating-point array. Depth of the output array is determined by thedtype parameter.

Note

Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.


How to scan images, lookup tables and time measurement with OpenCV

How to set all pixels of an OpenCV Mat to a specific value?

  • For grayscale image:

    cv::Mat m(100, 100, CV_8UC1); //gray m = Scalar(5);  //used only Scalar.val[0] 

    or

    cv::Mat m(100, 100, CV_8UC1); //gray m.setTo(Scalar(5));  //used only Scalar.val[0] 

    or

    Mat mat = Mat(100, 100, CV_8UC1, cv::Scalar(5));
  • For colored image (e.g. 3 channels)

    cv::Mat m(100, 100, CV_8UC3); //3-channel m = Scalar(5, 10, 15);  //Scalar.val[0-2] used 

    or

    cv::Mat m(100, 100, CV_8UC3); //3-channel m.setTo(Scalar(5, 10, 15));  //Scalar.val[0-2] used 

    or

    Mat mat = Mat(100, 100, CV_8UC3, cv::Scalar(5,10,15));

initialize an OpenCV Mat with an 2D array


What are the differences between CV_8U and CV_32F and what should I worry about when converting between them?

how to find out what type of a Mat object is with Mat::type() in OpenCV

Backup by rsync

rsync -aP --link-dest=PATHTO/$PREVIOUSBACKUP $SOURCE $CURRENTBACKUP

Lets go through the parameters step by step.

  • -a means Archive and includes a bunch of parameters to recurse directories, copy symlinks as symlinks, preserve permissions, preserve modification times, preserve group, preserve owner, and preserve device files. You usually want that option for all your backups.
  • -P allows rsync to continue interrupted transfers and show a progress status for each file. This isn’t really necessary but I like it.
  • --link-dest this is a neat way to make full backups of your computers without losing much space. rsync links unchanged files to the previous backup (using hard-links, see below if you don’t know hard-links) and only claims space for changed files. This only works if you have a backup at hand, otherwise you have to make at least one backup beforehand.
  • PATHTO/$PREVIOUSBACKUP is the path to the previous backup for linking. Note: if you delete this directory,no other backup is harmed because rsync uses hard-links and the operating system (or filesystem) takes care of releasing space if no link points to that region anymore.
  • $SOURCE is the directory you’d like to backup.
  • $CURRENTBACKUP is the directory to which you’d like to make the backup. This should be anon-existing directory.

Miscellaneous Image Transformations





0 0
原创粉丝点击