opencv videocapture empty frame - visual-studio-2010

i'm trying to acquire image from an wireless cam with EasyCAP tuner. I can get images with any other video capture programs and matlab but in opencv i get empty frames. This code worked with my laptop webcam and with a logitec webcam. With tuner it sends me in infinite loop here beacuse of empty frame.
while (frame.empty())
cap>>frame;
I'm using visual stuido 2010 , i have tuner on the 2nd slot(first is webcam)and my code is:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <windows.h>
#include <stdio.h>
using namespace cv;
using namespace std;
VideoCapture cap(1);
Mat frame;
void main()
{
char key;
namedWindow("imag", WINDOW_AUTOSIZE);
Sleep(1000);
cap.set(CV_CAP_PROP_FRAME_WIDTH,160);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,120);
cap.set(CV_CAP_PROP_FPS,15);
cap.set(CV_CAP_PROP_FOURCC,CV_FOURCC('B', 'G', 'R', '3'));
while (1)
{
cap>>frame;
while (frame.empty())
cap>>frame;
imshow("imag",frame);
waitKey(33);
}
}
without set proprieties is the same

Related

How fix my codeblocks compile programm use fstream, cannot open files large 20 mbs?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
char fileInputPath[256] = "D:\25mb.file";
ifstream fileInput(fileInputPath, ios::in|ios::binary);
if (fileInput.is_open() != true) cout << "File not opened.\n";
return 0;
}
programm result:
File not opened
tesing system win7 x32

debug openCV with qt creator on ubuntu 14.04

I try to debug some openCV code with qt creator on Ubuntu 14.04
But if i step through the lines the debugger don't step into the openCV files.
This is the code want to debug
#include <QCoreApplication>
#include <stdio.h>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[]) {
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2;
FastFeatureDetector fast = FastFeatureDetector(); <-----
vector<KeyPoint> kp;
fast.detect(img_1,kp); <------
Scalar color = (255,0,0);
drawKeypoints(img_1,kp,img_2,color);
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", img_2 );
waitKey(0);
return -1;
}
I will step into the openCV files I comment with "<-----"
Thanks for the help

Can I "push" a boost::iterator onto a boost iostream

I managed to get working:
1) a base 64 encoder/decoder using boost::archive::iterators derived from
Base64 encode using boost throw exception
2) a compressor using boost::iostreams as shown here:
boost zlib problem
So code the looks like this:
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/remove_whitespace.hpp>
namespace io = boost::iostreams;
namespace it = boost::archive::iterators;
typedef it::transform_width< it::binary_from_base64<std::string::const_iterator >, 8, 6 > it_binary_t;
typedef it::base64_from_binary<it::transform_width<std::string::const_iterator ,6,8> > it_base64_t;
// Compress
std::stringstream binary_in;
binary_in << data...;
std::stringstream binary_out;
io::filtering_streambuf<io::output> outStream;
outStream.push(io::zlib_compressor());
outStream.push(binary_out);
io::copy(binary_in, outStream);
// base64 Encode
std::string s = binary_out.str();
unsigned int writePaddChars = (3-s.length()%3)%3;
std::string base64(it_base64_t(s.begin()),it_base64_t(s.end()));
base64.append(writePaddChars,'=');
That seems to much copying data.
Is there a way to push the base64 encoder onto the iostream?

How to extract multiple lines from an image using Tesseract OCR?

We have passed an image with single line having the text "Hello World" and the Tesseract OCR perfectly show the result 'Hello World'.
But when we passed an image with multiple lines text
Hello world
How are you
it doesn't show anything.
Here is our codes:
#include "stdafx.h"
#include <iostream>
#include <baseapi.h>
#include <allheaders.h>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
tesseract::TessBaseAPI api;
api.Init("", "eng", tesseract::OEM_DEFAULT);
api.SetPageSegMode(static_cast<tesseract::PageSegMode>(7));
api.SetOutputName("out");
cout<<"File name:";
char image[256];
cin>>image;
PIX *pixs = pixRead(image);
STRING text_out;
api.ProcessPages(image, NULL, 0, &text_out);
cout<<text_out.string();
ofstream files;
files.open("out.txt");
files << text_out.string()<<endl;
files.close();
cin>> image;
return 0;
}
input with 1 line
output with 1 line
input with 2 lines
output with 2 lines
Page Segmentation Mode 7 treats the image as a single text line. Try 3, which is Fully automatic page segmentation, but no OSD (default).

OpenCV cannot load image

While I was working on a project, I noticed that I am not able to load images. Here is the simple code that I used to check:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
Mat gray_image;
cv::cvtColor(image, gray_image, CV_RGB2GRAY);
imwrite("Gray_Image.jpg",gray_image);
return 0;
}
Here is its output when I execute it:
root#beaglebone:~# ./tryit lena.jpg
Could not open or find the image
I tried to directly use the address of the image ("/home/root/lena.jpg") instead of argv[1] but nothing changed.
What can be the problem?
ps: I am cross-compiling this OpenCV program and then running it on my BeagleBone which has Angstrom Linux installed on it. Can this problem related to it?
I solved my problem by deleting existing OpenCV libraries on my angstrom image and replacing them with the working ones.
Try saving the image with a png extension and then opening it. For some reason, files with a png extension work better than other extensions like jpg/gif.

Resources