Results 1 to 4 of 4

Thread: OpenCV

  1. #1
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default OpenCV

    Hi everybody i have a problem
    Qt Code:
    1. #include <opencv2/imgproc/imgproc.hpp>
    2. #include <opencv2/highgui/highgui.hpp>
    3. #include <QtCore>
    4. #include <iostream>
    5. using namespace cv;
    6. using namespace std;
    7.  
    8. int main()
    9. {
    10. Mat src = imread(String("qrc://balls.jpg"), CV_LOAD_IMAGE_COLOR);
    11. if (src.empty())
    12. {
    13. cout << "cannot load" << endl;
    14. return -1;
    15. }
    16.  
    17.  
    18. Mat hsv;
    19. cvtColor(src, hsv, CV_BGR2HSV);
    20.  
    21. Mat bw;
    22. inRange(hsv, Scalar(19, 204, 153), Scalar(27, 255, 255), bw);
    23.  
    24. vector<vector<Point> > contours;
    25. findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    26.  
    27. Mat dst = Mat::zeros(src.size(), src.type());
    28. drawContours(dst, contours, -1, Scalar::all(255), CV_FILLED);
    29.  
    30. dst &= src;
    31.  
    32. imshow("src", src);
    33. imshow("dst", dst);
    34. waitKey(0);
    35. int a;
    36. cin >> a;
    37.  
    38. return 0;
    39. }
    To copy to clipboard, switch view to plain text mode 
    and resource file
    Qt Code:
    1. <RCC>
    2. <qresource prefix="/">
    3. <file>balls.jpg</file>
    4. </qresource>
    5. </RCC>
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by Viper666; 31st January 2013 at 19:13.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenCV

    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.

  3. #3
    Join Date
    Jul 2012
    Posts
    123
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenCV

    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

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenCV

    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.

Similar Threads

  1. OpenCV + QT4
    By thereisnoknife in forum Qt Programming
    Replies: 6
    Last Post: 8th March 2013, 05:19
  2. opencv-qt-mac
    By ireneluis in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2010, 15:24
  3. Qt and OpenCV
    By malorie in forum Newbie
    Replies: 2
    Last Post: 7th March 2010, 14:57
  4. OpenCv & Qt4
    By switch in forum Qt Programming
    Replies: 0
    Last Post: 4th August 2009, 15:12
  5. JAI vs. OpenCV vs. ITK
    By tpieciak in forum General Programming
    Replies: 0
    Last Post: 8th July 2009, 13:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.