Ask Your Question

black's profile - activity

2014-04-30 10:15:16 -0500 commented question Raw read fails

Am I forgetting any point?

2014-04-22 13:39:43 -0500 asked a question Raw read fails

Hello,

When you need to read an image from disk, you go for imread. Nevertheless, I need to istantiate a Mat using raw data. Consider this code:

#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>

int main()
{
 std::string path;
 std::cout << "Path: ";
 std::getline(std::cin, path);

 std::ifstream file(path, std::ifstream::binary); // raw data
 if (!file.is_open())
 {
   std::cout << "Could not open file." << std::endl;
  return 1;
 }

  file.seekg(0, file.end);
   auto fileSize = file.tellg();
  file.seekg(0, file.beg);

  std::cout << fileSize << "." << std::endl;

  std::unique_ptr<unsigned char> bufferPtr(new unsigned char[fileSize]);
 file.read(reinterpret_cast<char *>(bufferPtr.get()), fileSize);

 if (!file)
  {
    std::cout << "Could not read all data." << std::endl;
   return 1;
  }

 std::cout << "Enter file width: "; //how can I figure this
 int width;
 std::cin >> width;

 std::cout << "Enter file height: "; // and this out?
 int height;
 std::cin >> height;

 std::vector<unsigned char> buffer( bufferPtr.get(), bufferPtr.get() + fileSize);

 cv::Mat img(height, width, CV_8UC3, buffer.data());
 // as well as              ^^^^^^^ this ?
 if (img.empty())
 {
   std::cerr << "Could not load Mat object." << std::endl;
  return 1;
 }

 cv::namedWindow("window", CV_WINDOW_AUTOSIZE);
 cv::imshow("window", img);

 cv::waitKey(0);
 return 0;
}

It works most of the times indefinitely: sometimes it crashes (SIGSEGV when converting the format), sometimes shows wrong stuff.
Where am I wrong? How can I get stuff like width, height and the format as imread does?

2014-02-13 09:52:15 -0500 asked a question Find out where Mat is compressed

Hello,

I need to know where a certain Mat was compressed or not by the sender because, if so, I've to decode it first and then show it.
Say we have a 640 x 480 frame that's using CV_8UC3; its uncompressed size is 921600 bytes. How would you figure out if it was compressed or not?

I tried to compare its size (that I receive before reading it) with 640 * 480 * CV_8UC3, but it does not work because, for some reason, on my system CV_8UC3 has the value 16 instead of 3. (#define CV_8UC3 CV_MAKETYPE(CV_8U,3))
The most obvious way would be sending a simple sort of message informing that it was compressed, but I would like to know if there was a faster and smarter way.

2014-02-08 10:18:59 -0500 received badge  Supporter (source)
2014-01-31 08:41:22 -0500 commented question Dealing with RaspiCamCV

You should. Raspivid is able to both show and write to disk a 30 FPS 1080p stream. It's the overhead or the bad implementation. I have to say though, that I won't have to show the frames but send them over the network, which is lighter. Later I will try some other libraries. I'm gonna keep you updated.

2014-01-31 01:02:56 -0500 received badge  Student (source)
2014-01-30 10:56:26 -0500 received badge  Editor (source)
2014-01-29 09:18:20 -0500 commented question Dealing with RaspiCamCV

I'm trying to figure that out. I have sincerely hoped that someone already worked with those libraries. However you're right: you cannot say that it works with OpenCV if with OpenCV you just mean grabbing and showing a frame.

2014-01-28 14:42:30 -0500 asked a question Dealing with RaspiCamCV

Hello,

I am going to develop a TCP client-server C++ application, using, of course, OpenCV. The server will run on a Raspberry Pi (aka rpi).
Today I have found out that the rpi camera module (v. 1.3) is not, unfortunately, natively supported by OpenCV. So, I will need to rely on a C++ wrapper class, named RaspiCamCV (you might have heard of it before).
What I want to basically know is: can I use freely OpenCV once I have dealt with the "exceptions" that let OpenCV interface with the camera module?
I could be a little broad, so I will be giving you an example:

RaspiCamCvCapture * cap = raspiCamCvCreateCameraCapture(0);

Since I can't use VideoCapture I need to use that way. But after that, can I use stuff like:

cap.get(CV_CAP_PROP_FRAME_WIDTH)

and

Mat frame;
cap.read(frame); 
imshow("...", frame);

?
Hopefully I have been enough clear. Please do not hesitate to ask any doubts. Thank you.

UPDATE

I'm using a library which is actually easy, but looks like that OpenCV is used just for imshow. Also there's a sensible overhead: in order to get a decent framerate I have to lower down the resolution to 640x480. I'm gonna try another one.
I might put the frames in a std::queue and show them with a separated thread too.

UPDATE #2

I tried this other library. I initially thought it could have given me better performance, because if you look at the source code, you will see it strictly interacts with C code (MMAL layer). But it gave me performance very little better, and for that I would suggest you the first one. Later I will take a look at raspivid source code: I want to find out where its performance comes from.