Cannot read image with See3CAM with Python 3 and open CV -


i trying read image camera e-con systems using python 3.4 , opencv. camera uses directshow drivers , can connect camera (isopened returns true , status led on camera active) when try read or grab frame not work.

import cv2 cam = cv2.videocapture(cv2.cap_dshow + device) cam.isopened()  # returns true, camera led on flag, frame = cam.read() # flag=false, frame=none 

i have tried capturing multiple frames others have stated, still no luck!

as can see camera specification, camera output format y16 i.e. 16-bit monochrome format. default opencv / direct show not support format!

building opencv see3cam custom format

here step step procedure build opencv custom frame format support.

  1. download opencv
  2. download modified cap_dshow.cpp.

note: source code modified supporting y16 & by8 formats only.

  1. select required configuration- building x86 or x64 bit library , build opencv official guide.

  2. replace existing cap_dshow.cpp

i. opencv 2.x.x path: opencv/sources/modules/highgui/src

ii. opencv 3.x.x path: opencv/sources/modules/videoio/src

  1. open opencv.sln solution file & build opencv library.

here sample c++ application streaming camera 16-bit image format. hope simple port python! hope helps!

#include "ctimer.h" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <stdlib.h> #include <stdio.h> #include <iostream>  using namespace cv; using namespace std;  int main( int, char** argv ) {     const int iwidth=1280;     const int iheight=720;      ctimer t_fps;     t_fps.init();      videocapture capture(0);      if(!capture.isopened())     {         cout<< "cannot open camera!";         return 0;     }     capture.set(cv_cap_prop_frame_width,iwidth);     capture.set(cv_cap_prop_frame_height,iheight);      namedwindow("camera nir frame",window_autosize);      mat mcamframe_10,mcamframe_8;      char key;     for(;;)     {          capture >> mcamframe_10; // new frame camera          if(mcamframe_10.empty()||mcamframe_10.rows==0||mcamframe_10.cols==0)         {             cout<< "invalid frame frame empty"<<"\n";             break;         }          //convert 8 bit: scale 10 bit (1024) pixels 8 bit(256) (256/1024)= 0.25         convertscaleabs(mcamframe_10,mcamframe_8,0.25);          imshow("camera nir frame", mcamframe_8);          t_fps.update();         cout<<"frame rate: "<<t_fps.getfps()<<"\n";         key = cv::waitkey(1);         if(key == 27)         {             //esc key pressed & exit application             break;         }     }     waitkey(0);     return 0;     // camera deinitialized automatically in videocapture destructor } 

Comments