Webcam is not being detected in opencv - opencv

I am using opencv 2.3.1a in ubuntu 11.o4.
I installed opencv using: http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/
Since I could not use webcam with that installation. I changed "cmake" option from WITH_V4L=OFF to WITH_V4L=ON. But it still does not work.
I tried the following code:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( 0);
if(!capture)
{
printf("no camera");
return -1;
}
}
And yeah the output is : no camera
I do not know where the problem is.

I followed the steps mentioned in:
http://www.ozbotz.org/opencv-installation/
This solved the problem.

Related

Open cv gives a blank window with my USB camera

I was using my acer crystal eye camera until now. It was giving me the exact output as I need but when I moved into using my Logitech camera it gives me just a black window.
Nothing is wrong with my Logitech camera I am using it for skyping and even I tried the onlinemirror as well.
Can anybody help me. there were lot of solutions for this issue but nothing helped me.
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv) {
CvCapture *video = cvCaptureFromCAM(1);
IplImage * img = NULL
if(!cvGrabFrame(video)){
printf("could not grab a frame\n");
exit(0);
}
cvNamedWindow("original_image",0);
while(1){
img = cvQueryFrame(video);
cvShowImage("original_image",img);
if (cvWaitKey(0)==27){
break;
}
cvReleaseImage(&img);
cvReleaseCapture(&video);
return (EXIT_SUCCESS);
}
Try to use if (cvWaitKey(30)==27) works instead of if (cvWaitKey(0)==27)
The highgui needs some time to update the frame.
Are you sure that your usb camera has index 1?
CvCapture *video = cvCaptureFromCAM(1);
You could try to disable your acer webcam in the Device Manager (if you are using windows) and then replace the above line with:
CvCapture *video = cvCaptureFromCAM(CV_CAP_ANY);
This way, you make sure you only have 1 camera enabled(the usb camera), and by using CV_CAP_ANY you make sure that that one cam is used. If this still gives you a black/blank screen, you know something else is wrong.

Why would my OpenCV program on BeagleBone Black capture images like this?

Here is a link to the type of images my program produces: http://imgur.com/a/vibBx#0
I am trying out a simple capture test program that I have written. I am trying to capture images in a loop and save them onto the board properly numbered. The first capture sometimes is corrupted and the subsequent captures are a mix of two images. I have also observed that sometimes the upper half of the image is from the previous capture and the lower half is the capture from that cycle. I have given the details and the code below.
OpenCV 2.4.2 running on BeagleBone Black which has Ångström installed on it.
The camera which is plugged to the USB of BeagleBone Black is Logitech C920.
The camera is connected to BeagleBone Black before power up through the 5 V power supply and connecting BeagleBone Black to the laptop. Access is through PuTTY.
Code
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cxcore.h>
#include "LaserWeed.h"
#include "SimpleGPIO.h"
using namespace cv;
int main(int argc, char* argv[])
{
int i=0, a;
string name;
int length;
char c, Filename[10000];
CvCapture* capture = NULL;
IplImage* img = NULL;
do
{
//I am not sure if this is necessary, but I tried anyway
//to see if it makes a difference since upper half of
//image was from previous cycle.
capture = NULL;
img = NULL;
//Converting Numbers to string to save with proper name
std::stringstream ss;
ss << i;
name = ss.str();
name = name + ".jpg";
length = name.size();
for(a=0; a<length; a++)
{
Filename[a] = name[a];
}
capture = cvCaptureFromCAM(-1);
if (!capture)
{
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
img = cvQueryFrame(capture);
if (!img)
{
fprintf(stderr, "ERROR: img is null...\n");
getchar();
return -1;
}
cvSaveImage(Filename,img);
cvReleaseCapture(&capture);
cvReleaseImage(&img);
i++;
c = getchar();
}
while (c!='e')
;
return 0;
}
Where might I be going wrong?
The Stack Overflow question BeagleBone, OpenCV and webcam issue somewhat has a similar problem. But reinstallation of the OS will be my last option.
This is weird, anyway try to take the capture out of the do-while loop, maybe opening and releasing the capture device each time won't give enough time for the camera to prepare it's image buffers.

How can I use tesseract and opencv to extract the text from the camera

I'm using tesseract 3.02 and opencv to let the tesseract recognize the text from my camera realtime.
But the effect is quite bad. Results are unreadable and can't show image fluently. I think it's the problem of my code.
Can some one give me advice about how to modify it?
Thanks a lot!
#include "stdafx.h"
#include <string>
#include <opencv2/opencv.hpp>
#include <time.h>
using namespace std;
using namespace cv;
int main() {
// [1]
tesseract::TessBaseAPI *myOCR =
new tesseract::TessBaseAPI();
// [2]
printf("Tesseract-ocr version: %s\n",
myOCR->Version());
printf("Leptonica version: %s\n",
getLeptonicaVersion());
// [3]
if (myOCR->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
//声明IplImage指针
IplImage* pFrame = NULL;
//获取摄像头
CvCapture* pCapture = cvCreateCameraCapture(-1);
//创建窗口
cvNamedWindow("video", 1);
//显示视屏
time_t last_time = time(NULL);
while(1)
{
pFrame=cvQueryFrame( pCapture );
if(!pFrame) break;
cvShowImage("video",pFrame);
char c=cvWaitKey(33);
if(c==27)break;
time_t this_time = time(NULL);
if(this_time != last_time)
{
last_time = this_time;
myOCR->SetRectangle(0,0,pFrame->width,pFrame->height);
myOCR->SetImage((uchar*)pFrame->imageData,pFrame->width,pFrame- >height,pFrame->depth/8,pFrame->width*(pFrame->depth/8));
myOCR->Recognize(NULL);
const char* out = myOCR->GetUTF8Text();
printf("%s\n",out);
}
}
cvReleaseCapture(&pCapture);
cvDestroyWindow("video");
cv::waitKey(-1);
return 0;
}
Tesseract was designed to process scanned books. It operates on white pages where there is only black text, clearly seen with minimal distortions. Images are mostly Black & White. Your image is grey level so Tesseract will perform very very poor.
It is not a problem of your code but of Tesseract.
If you point your camera towards a book, you will be able to get the text (assuming image is focused) but if you want to read general text (like street signs, logo on someones T-shirt than there is no way to do it. Sorry to disappoint you.
However, if you want to recognize a specific text, like credit card numbers or street signs,
that you can do it.
Start by grabbing many imgages of your text.
Do a bit of
pre-processing on the image, convert it to BW,
train Tesseract on many examples.
And then it will be able to accomplish your task.

Why is the speed of AVI video increasing when reading it using OpenCV?

I am trying to read an AVI file using openCV. After getting the capture, the problem comes when I give a condition to the while loop which governs the extent to which queryFrame will be done.
There are total 1251 frames in the video.
When I use while (counter <= number_of_frames), the video runs fine and,
when I use while (cvQueryFrame(capture)), the video runs fine till 200-250th frame, then suddenly it starts running faster and finishes by 625th frame. I printed the FPS, it remains same all the time.
Why is this happening ??
Please help!
try the following...
C style reading..
#include <opencv2/video/video.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
CvCapture *video;
video = cvCreateFileCapture("ADDRESS TO THE FILE");
IplImage *frame;
while(true)
{
frame = cvQueryFrame(video);
if(frame->imageData==NULL)
{
std::cout<<"END OF VIDEO"<<std::endl;
break;
}
cvShowImage("VIDEO",frame);
cvWiatKey(25);//SINCE MOST OF THE VIDEOS RUN AT 25 FPS
}
return 0;
}
C++ STYLE....
int main()
{
VideoCapture video("ADDRESS OF VIDEO");
Mat frame;
while(true)
{
video >> frame;
if(frame.data==NULL)
{
std::cout<<"END OF VIDEO FILE"<<std::endl;
break;
}
imshow("VIDEO",frame);
waitKey(25);
}
return 0;
}
try this...and check if it gives an uniform rate of play...

Can't display an image (Win7 x64 Opencv 2.3)

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
int main()
{
cv::Mat im =cv::imread("C:/OpenCV2.3/opencv/samples/cpp/matching_to_many_images/query.png");
if(im.empty())
{
return -1;
}
cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
cv::imshow("image" , im);
cv::waitKey();
return 0;
}
After executing this code sample , i have gray window. Whean i move a cursor on the window, it shows , that something is loading. What's the problem? I'am sure that the imagepath is correct.
I had the same error. Turned out my system missed the msvcp100d.dll and msvcr100d.dll files.

Resources