Camera is not recognized
My problem is that the camera is not recognized.
I have tested Kamara with Chese and the program runs with videos. I have already googled and found nothing that fits
Sorry for my bad English
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/tracking/tracker.hpp>
#include <opencv2/tracking/tldDataset.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
// Convert to string
#define SSTR( x ) static_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
int main(int argc, char **argv)
{ // List of tracker types in OpenCV 3.4.1
string trackerTypes[8] = {"BOOSTING", "MIL", "KCF", "TLD","MEDIANFLOW", "GOTURN", "MOSSE", "CSRT"};
// vector <string> trackerTypes(types, std::end(types));
// Create a tracker
string trackerType = trackerTypes[2];
Ptr<Tracker> tracker;
if (CV_MINOR_VERSION < 3)
{
tracker = TrackerMIL::create();// tracker = Tracker::create(trackerType);
}
else
{
if (trackerType == "BOOSTING")
tracker = TrackerBoosting::create();
if (trackerType == "MIL")
tracker = TrackerMIL::create();
if (trackerType == "KCF")
tracker = TrackerKCF::create();
if (trackerType == "TLD")
tracker = TrackerTLD::create();
if (trackerType == "MEDIANFLOW")
tracker = TrackerMedianFlow::create();
if (trackerType == "GOTURN")
tracker = TrackerGOTURN::create();
if (trackerType == "MOSSE")
tracker = TrackerMOSSE::create();
if (trackerType == "CSRT")
tracker = TrackerCSRT::create();
}
// Read video
VideoCapture video ;
video.open(-1);//video.open( "/dev/video0");
cout << "OpenCV version : " << getBuildInformation() << endl;
// Exit if video is not opened
if(!video.isOpened())
{
cout << "Could not read video file" << endl;
cout << "OpenCV version : " << CV_VERSION << endl;
cout << "Major version : " << CV_MAJOR_VERSION << endl;
cout << "Minor version : " << CV_MINOR_VERSION << endl;
cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl;
return 1;
}
// Read first frame
Mat frame;
bool ok = video.read(frame);
// Define initial bounding box
Rect2d bbox(287, 23, 86, 320);
// Uncomment the line below to select a different bounding box
// bbox = selectROI(frame, false);
// Display bounding box.
rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
imshow("Tracking", frame);
tracker->init(frame, bbox);
while(video.read(frame))
{
// Start timer
double timer = (double)getTickCount();
// Update the tracking result
bool ok = tracker->update(frame, bbox);
// Calculate Frames per second (FPS)
float fps = getTickFrequency() / ((double)getTickCount() - timer);
if (ok)
{
// Tracking success : Draw the tracked object
rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
}
else
{
// Tracking failure detected.
putText(frame, "Tracking failure detected", Point(100,80), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0,0,255),2);
}
// Display tracker type on frame
putText(frame, trackerType + " Tracker", Point(100,20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50),2);
// Display FPS on frame
putText(frame, "FPS : " + SSTR(int(fps)), Point(100,50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50), 2);
// Display frame.
imshow("Tracking", frame);
// Exit if ESC pressed.
int k = waitKey(1);
if(k == 27)
{
break;
}
}
video.release();
destroyAllWindows();
}
OpenCV version :
General configuration for OpenCV 4.0.0-pre =====================================
Version control: 4.0.0-beta-41-geb981cc7d
Extra modules:
Location (extra): /opt/opencv_contrib/modules
Version control (extra): 4.0.0-beta-4-gfd63e177
Platform:
Timestamp: 2018-10-26T08:48:21Z
Host: Linux 4.15.0-36-generic x86_64
CMake: 3.10.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: RELEASE
CPU/HW features:
Baseline: SSE ...
Could it be this ?
"camera is not recognized." Have you got an error message ?
idk. why it is so, but the VideoIO section does not have any entries for V4L/V4L2.
can you try to set an env var
OPENCV_VIDEOIO_DEBUG=1
, and start your prog again ?(it should print out the order of backends tried)
I get this error without catch terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.0.0-pre) /opt/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
I found that with OPENCV_VIDEOIO_DEBUG = 1
[ INFO:0] VIDEOIO: Enabled backends(3, sorted by priority): FFMPEG(1000); CV_IMAGES(990); CV_MJPEG(980)
try basic sample
i got ERROR! Unable to open camera. in basic code.
@hcl, for one reason or another, you don't have any backend to use your webcam built into the opencv libs. (FFMPEG, CV_IMAGES, CV_MJPEG can only be used with video files or images)
the code you try with is not the problem here.
@berak Do you have a good tutorial on how to do it with gstreamer?
@hcl, sorry, not really. but you can use:
VideoCapture(id, CAP_GSTREAMER)
or evenVideoCapture("a ! whole ! pipeline")
but all of that ofc.assumes, that you rebuild the opencv libs with gstreamer-dev packages installed before
i have install gstream
GStreamer: -- base: YES (ver 1.14.1) -- video: YES (ver 1.14.1) -- app: YES (ver 1.14.1) -- riff: YES (ver 1.14.1) -- pbutils: YES (ver 1.14.1) -- v4l/v4l2: linux/videodev2.h
but my Programm sayVideo I/O: DC1394: NO FFMPEG: YES avcodec: YES (ver 57.107.100) avformat: YES (ver 57.83.100) avutil: YES (ver 55.78.100) swscale: YES (ver 4.8.100) avresample: NO GStreamer: NO
hmm, we'd need to see the full cmake output (there must be something at the beginning, where it's looking for your gstreamer install, but doesn't find it (or thinks it's not ok)