OpenCV invalid operands error - c++

I'm trying to compile some OpenCV code without success. So please if you can help me It would be really nice.
This is the code:
cv::Vec3b c = my_cv_mat.at<cv::Vec3b>(i, j) / interval;
cv::Vec3b t = another_cv_mat.at<cv::Vec3b>(i, j) / interval;
The error is:
Invalid operands to binary expression ('cv::Vec<unsigned char,3>' and 'int')
One thing to note is that I am compiling an iOS app with OpenCV support.Any ideas how can I fix this?. I already checked the source code and it's exactly the same as other projects which are working fine.
Thanks a lot.

Is your my_cv_mat and your another_cv_mat an image with three channels? If it is not your code will probably result in an error or return bogus values. You are probably using a grayscale or binary image. In that case use cv::uchar in stead of cv::Vec3b.

Related

cellstr function is not working in matlab

The following code works perfectly with octave, but I'm having trouble getting it to work in Matlab. If anyone can explain the difference and how to fix the code in Matlab, that would be wonderful.
n = 10;
class(n)
ans = double
cellstr(n)
Matlab error code
Error using cellstr (line 49)
Conversion to cellstr from double is not possible.
Thank you

Cannot convert OpenCV Mat to dlib arrray2D

I am using the following code to convert an cv::Mat into dlib array2D (which is required to track objects through dlib correlation tracker)
int main()
{
cv::Mat img = cv::imread("wine_plant.jpg");
dlib::cv_image<dlib::bgr_pixel> dlib_img(img);
return 0;
}
But while debugging I get the following error message.
Error C2440 'initializing': cannot convert from 'const cv::Mat' to 'IplImage' yolo_cywine c:\users\antho\documents\c++\dlib-19.7\source\dlib\opencv\cv_image.h 37
Based on other issues already opened on the same matter, I also tried this
cv::Mat img = cv::imread("wine_plant.jpg");
dlib::cv_image<unsigned char> dlib_img(img);
But same result.
Am I missing something or is there something I am doing wrong? Could you please help me out?
Thanks in advance.
Your dlib version 19.7 seems too old. I also faced similar error on dlib 19.19 downloading from its website. It was fixed on github, but http://dlib.net/ did not contain the fixes when I used it. For me compiling from source solved it. Newer dlib version should fix this error.
These issues discuss this problem,
https://github.com/davisking/dlib/issues/1955
https://github.com/davisking/dlib/issues/1949
https://github.com/davisking/dlib/issues/2071
Changes to cv_image.h,
https://github.com/davisking/dlib/commits/master/dlib/opencv/cv_image.h
https://github.com/davisking/dlib/commit/54a9a5bbf3267386dd39a82fb792bab1bb60796c#diff-7c8f1a39b770981bf2d3a132da6f083b130b7c52cd994dbccb1d2115f0d729fd
https://github.com/davisking/dlib/commit/a4bf6e1e6afef5c55414164dc4414908d91a8be5#diff-7c8f1a39b770981bf2d3a132da6f083b130b7c52cd994dbccb1d2115f0d729fd

FREAK is not a member of cv?

I am trying a code from tutorial to test the marker-less AR experience with OpenCV + OpenGL. But the problem is that when I compiled the code I found out that there is an error with the following segment of code:
cv::Ptr<cv::DescriptorExtractor> extractor = cv::FREAK(false, false),
and the error is:
FREAK is not a member of cv.
So, can someone tell me why is that happening? I have tried to search for a solution and tried to solve as much as I can but every time I got error.

Assertion sv_count !=0 failed - Function train_auto, SVM type - EPS_SVR

The question is related to the OpenCV library, version 2.4.13.2.
I am using n dimensional feature vectors from images for training and performing regression. The output values range between 0 and 255.
The function CvSVM::train works without an error, but requires a manual setting of parameters. So, I would prefer using the function CvSVM::train_auto to perform cross validation and determine the best parameters for the situation.
But I am facing the error:
OpenCV Error: Assertion failed (sv_count != 0) in CvSVM::do_train.
On changing the type to NU_SVR, it works well. The problem is only with type EPS_SVR.
I would appreciate any help I could receive to fix this.
EDIT: I was able to pinpoint the problem to line Number 1786 in the file-
opencv-master\sources\modules\ml\src\svm.cpp
FOR_IN_GRID(p, p_grid)
Upon commenting it, the code runs without errors. I am unaware of the reasons possible.
Facing the same bug. Found out that this bug was caused by svm.setP(x) and svm.setTermCriteria((cv2.TERM_CRITERIA_EPS, y)) where x and y values more than 0.1 (10^-1).

Eigen code fail in release mode but work in debug mode

Hi everyone who use Eigen, I encountered a strange question here.
I implemented a Unscented Kalman Filter with Eigen.
It works very well on my PC, but the same piece of code will generate segmentation fault on my embedded system, Odroid XU (Armv7 Architecture).
After hours of debugging, I found the problem was with this part:
qrSolver.compute(OS.transpose());
m_q=qrSolver.householderQ();
m_r = qrSolver.matrixQR().triangularView<Upper>();
S_pre = m_r.block(0,0,n,n).transpose();
if (w_c0 < 0)
internal::llt_inplace<float,Upper>::rankUpdate(S_pre,
sqrt(-w_c0)*(sigmaPoints.col(0) - state_pre),
-1);
else
internal::llt_inplace<float,Upper>::rankUpdate(S_pre,
sqrt(w_c0)*(sigmaPoints.col(0) - state_pre),
1);
where I first compute the QR decomposition of matrix OS (dimension n-by-3n), and then perform rank update of its R component (dimension n-by-n). internal::llt_inplace::rankUpdate is a function in Eigen library which is not documented. It just perform rank-1 update to its first argument. This function can be found in ~/path_to_Eigen/Cholesky/LLT.h
The most strange thing of this piece of code is, with -DCMAKE_BUILD_TYPE=Debug it works perfectly, while if I compile with -DCMAKE_BUILD_TYPE=Release, this code fails.
I would like to ask can anyone understand this or does anyone have similar issue before. Please help, thanks a lot.