PDA

View Full Version : OpenCV



Viper666
31st January 2013, 19:40
Hi everybody i have a problem

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <QtCore>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
Mat src = imread(String("qrc://balls.jpg"), CV_LOAD_IMAGE_COLOR);
if (src.empty())
{
cout << "cannot load" << endl;
return -1;
}


Mat hsv;
cvtColor(src, hsv, CV_BGR2HSV);

Mat bw;
inRange(hsv, Scalar(19, 204, 153), Scalar(27, 255, 255), bw);

vector<vector<Point> > contours;
findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

Mat dst = Mat::zeros(src.size(), src.type());
drawContours(dst, contours, -1, Scalar::all(255), CV_FILLED);

dst &= src;

imshow("src", src);
imshow("dst", dst);
waitKey(0);
int a;
cin >> a;

return 0;
}

and resource file

<RCC>
<qresource prefix="/">
<file>balls.jpg</file>
</qresource>
</RCC>

but it never load image i dont know what is wrong
But QImage load it but i dont know how convert it to Mat static_cast doesnt work

d_stranz
1st February 2013, 01:24
The url "qrc://" probably has no meaning in OpenCV. QImage knows how to translate this url and understands that it means, "look in the compiled resources for this file and load the image from it".

The solution? Two possibilities: (1) Don't build the file into compiled resources, make it a disk file. (2) Use QImage to read it from compiled resources, then convert the bits into something that OpenCV can understand. I am sure there is a way to do that.

Viper666
1st February 2013, 13:15
i tryed open it from disk too i have this image iin same folder and i try imread("balls.jpg"); but it doesn't work too

d_stranz
1st February 2013, 17:59
Then this is no longer a Qt question, it is an OpenCV problem.

(1) How do you know that imread() is looking for your JPG file in the folder where you have it? Use the absolute path to see if that works ("C:\\MyFolder1\\MyFolder2\\balls.jpg" or whatever).

(2) Does imread support JPG format? Does OpenCV need a plugin to read JPG format (like Qt does)?

If using the absolute path (in (1)) does not work, then it is an OpenCV problem and you need to find an OpenCV forum to ask your questions.