OpenCV Tips

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 the dtype 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 a non-existing directory.

Miscellaneous Image Transformations





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值