martedì 13 dicembre 2016

How to read a image sequence with OpenCV


This rough post contains information about the stored image sequence management for still images processing in OpenCV. This post is a reminder, not a tutorial.

Simple assumptions


  • Your image sequence contains images with file name like this: image000001.png. Normally you store images with this sequential file name convention (consider also the case of auto file naming)
  • Your images are in png format (It is only for this example)
  • Your folder absolute path is /folder1/folder2/folder3/ (please consider that Unix and Win paths are different, so use carefully the \ or / chars)


ImageList file

you can use the image list file creator inside the opencv samples, to build a xml file containing the list of the images inside the target folder.
Then you can import the list of images as a vector inside your code

VideoCapture

0. some variables
cv::Mat image_frame;
std::string str_sequenceFileName = "/folder1/folder2/folder3/image%06d.png ";

1. create a videocapture object and then open it, check if is opened and eventually send an error on the shell.

cv::VideoCapture videoCapture;
videoCapture.open(str_sequenceFileName); // open the default camera
if (!videoCapture.isOpened()) {  // check if we succeeded
std::cerr << "[EE] opening video capture OFFLINE device" << std::endl;
return -1;
}
}

2. use the videocapture object instance to grab the current frame. the videocapture grabs the frame from the image sequence folder. You can use it directly inside your main image processing loop.

videoCapture >> image_frame;

Glob

0. some variables
cv::String str_sequenceFolder = "/folder1/folder2/folder3"
cv::String glob_folder = str_sequenceFolder + "/*.png";
std::vector<cv::String> imageFileNamesList;
imageFileNamesList.clear();
cv::Mat image_frame;

1. fill the vector with the image names inside the sequence folder, to obtain the image names list vector

cv::glob(glob_folder, imageFileNamesList);

2. sort the vector (maybe it is not useful)

std::sort(imageFileNamesList.begin(), imageFileNamesList.end());

3. read the current image from the sequence folder

for (int n_frameNumber=0; n_frameNumber < imageFileNamesList.size(); ++n_frameNumber) 
{
    image_frame = cv::imread(imageFileNamesList[n_frameNumber]);
    //some image processing
}

mercoledì 8 giugno 2016

String with padded number in c++

How to use a padded number in a string in c++??

ok, I need to use it to number a image sequence.

Here the include statements
#include <iomanip> // for setfill etc
#include <string>     // for string
#include <sstream>  // for stringstream

Some variables:

std::stringstream sStream;
std::string m_frameName;
int m_frameNumber;

Finally the key piece of code

sStream << std::setfill('0') << std::setw(6) << m_frameNumber;sStream >> m_frameName;

std::cout << "=========" << std::endl << "Frame no. " << m_frameNumber <<  std::endl;
std::cout << "[DBG] " << "m_frameName: " << m_frameName << std::endl;


venerdì 12 febbraio 2016

Ubuntu 14.04 LTS on Dell inspiron 15 7000 series



subtitle: a lot of problems





ok, this is the page of the hardware configuration certification in ubuntu
http://www.ubuntu.com/certification/catalog/component/dmi/4755/dmi%3ADellSystemInspiron157000Series7537/


...but...

WI FI

when you finish the installation stage, u could have no wireless connection
due to problems with Intel wireless drivers

on the Dell pc you have this wireless card
Intel® Wireless 7265
Intel® Wireless 3165 (starting from firmware XX.XX.13.0 and kernel 4.1)

https://wireless.wiki.kernel.org/en/users/Drivers/iwlwifi


a solution is to use this trick:


First, verify that you have these two files; iwlwifi-7265D-13.ucode and iwlwifi-7265-13.ucode:
ls /lib/firmware | grep 7265
If so, we are going to make copies but rename them:
cd /lib/firmware
sudo cp iwlwifi-7265D-13.ucode  iwlwifi-3165-9.ucode
sudo cp iwlwifi-7265-13.ucode  iwlwifi-3165-13.ucode

FROM: http://askubuntu.com/questions/672700/how-can-i-install-intel-dual-band-wireless-ac-3165-drivers

This solution works for me.


Kernel 4.X

you could have problems with this kernel
in my case the nouveau drivers crash on startup 


FREEZING


sometimes the OS freezes,

I don't be sure that this is the solution...

If you have installed the Ubuntu distro on a PC with Microsoft Windows pre-installed maybe the fast startup settings could be put on the RAM some configuration files, then when you start linux it could be find a incoerent state...
 
try to disable the hybernate and sleep, and fast startup in windows OS


I tryed also to install other kernels or other versions of  ubuntu and mint, but I cannot have more than half an hour to spend in installations...