void OpenniGetColorPoints(CvCapture* capture, std::vector<ColorPoint>* points, IplImage* maskImg) { IplImage* pcm = cvRetrieveFrame(capture, CV_CAP_OPENNI_POINT_CLOUD_MAP); //XYZ in meters (CV_32FC3) IplImage* bgr = cvRetrieveFrame(capture, CV_CAP_OPENNI_BGR_IMAGE); //CV_8UC3 int ptCount = pcm->width * pcm->height; CvPoint3D32f* position = (CvPoint3D32f*)pcm->imageData; unsigned char* color = (unsigned char*)bgr->imageData; //int colorIdx = 0; ColorPoint cp; if (maskImg) { unsigned char* mask = (unsigned char*)maskImg->imageData; for (int i = 0; i < ptCount; i++, mask++, position++, color += 3) if (*mask) { memcpy(&cp.position, position, sizeof(CvPoint3D32f)); memcpy(&cp.red, color, 3); points->push_back(cp); } } else { for (int i = 0; i < ptCount; i++, position++, color += 3) { memcpy(&cp.position, position, sizeof(CvPoint3D32f)); memcpy(&cp.red, color, 3); points->push_back(cp); } } }
void WebCam::captureImg() { std::stringstream path; path<<"scan/capture/"<< saveCount <<".png"; cvRetrieveFrame(capture); cvSaveImage(path.str().c_str(), cvRetrieveFrame(capture)); saveCount++; }
int main() { IplImage* image = 0; IplImage* reverse = 0; CvCapture* video = cvCaptureFromCAM(-1); cvNamedWindow("Original Video",0); cvNamedWindow("Reverse Video",0); while(1) { cvGrabFrame(video); image = cvRetrieveFrame(video); cvShowImage("Original Video",image); reverse = cvCreateImage(cvGetSize(image),image->depth,image->nChannels); cvNot(image,reverse); if(cvWaitKey(10) >=0) break; reverse->origin=image->origin; cvShowImage("Reverse Video",reverse); } cvReleaseImage(&reverse); cvReleaseCapture(&video); cvDestroyWindow("Reverse Video"); cvDestroyWindow("Original Video"); return 0; }
Image * USBCamera::takeImage() { // Update camera, call executor's functor. tryToUpdateCapture(); // Take image try { // Delay camera for some time.. usleep(m_delay*1000); // Get image from camera Image * image = new Image(); cvGrabFrame(m_camera); cvGrabFrame(m_camera); cvGrabFrame(m_camera); cvGrabFrame(m_camera); cvGrabFrame(m_camera); // workaround for buffering image->setImage(cvRetrieveFrame(m_camera)); // Check if need to rotate the image image->rotate(m_angle); return image; } catch(cv::Exception & ex) { throw OpenCVException(ex.msg.c_str()); } }
/* Tool function */ void motionDetection::accFrameFromVideo(CvCapture* capture){ //cvNamedWindow( "Video", CV_WINDOW_AUTOSIZE ); // Create a window to display the video while (mCount != mFrameNumber) { if (cvGrabFrame(capture)) { mFrame = cvRetrieveFrame(capture); // convert rgb to gray cvCvtColor(mFrame, mpFrame[mCount], CV_BGR2GRAY); // accumulate each frame cvAdd(mSum, mpFrame[mCount], mSum); //cvShowImage( "Video", mpFrame[mCount] ); // display current frame ++mCount; if (cvWaitKey(10) >= 0) { break; } } else { break; } } //cvDestroyWindow( "Video" ); }
static u32 OCV_Run(void *par) { IplImage* image; CvCapture *capture; GF_InputSensorDevice *ifce = (GF_InputSensorDevice *)par; GF_OpenCV *ocv = (GF_OpenCV *)ifce->udta; capture= cvCaptureFromCAM(0); cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH,640 ); cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 ); cvNamedWindow( "test", 0 ); image = NULL; while (ocv->running) { if (cvGrabFrame(capture)) { CvHaarClassifierCascade* cascade; image = cvRetrieveFrame(capture); cascade = load_object_detector("haarcascade_frontalface_default.xml"); detect_and_draw_objects(ifce, image, cascade, 1 ); cvShowImage( "test", image ); cvWaitKey(40); } } if (image) cvReleaseImage( &image); return 0; }
void USBCamReader::readCurFrameGray(unsigned char* grayImgData) { assert(videoCap); IplImage* img = cvRetrieveFrame(videoCap); cv::Mat rawFrame(img); cv::Mat videoFrame(_h, _w, CV_8UC1, grayImgData); cv::cvtColor(rawFrame, videoFrame, CV_RGB2GRAY); }
int main(){ //initialize IplImage *frame; CvCapture *video = cvCaptureFromFile("/Users/ihong-gyu/MyProject/OpenCVTest/video.mp4"); //create window cvNamedWindow("Video",0); //show video while(1){ cvGrabFrame(video); frame = cvRetrieveFrame(video); //null checker if(!frame) break; cvShowImage("Video", frame); //wait key input if(cvWaitKey(10)>=0) break; } //release memory cvReleaseCapture(&video); return 0; }
void Capture::update() { cvGrabFrame(m_capture); IplImage *frame = cvRetrieveFrame(m_capture); TmpBufferImage btmp(CV_8UC3); if ( frame != NULL ) { CvMat *mat = cvCreateMat(frame->height, frame->width, CV_8UC3); if ( m_invert ) { CvMat *tmp = btmp.getImage(frame->width, frame->height); cvConvertImage(frame, tmp, CV_CVTIMG_SWAP_RB); InvertImage(tmp, mat); } else { cvConvertImage(frame, mat, CV_CVTIMG_SWAP_RB); } m_wpipe.write(mat); } }
/* read the next camera frame to R G and B chanel arrays to be then * used by an RVC-CAL actor compiled with Orcc */ void readCameraFrame(uchar *rArr, uchar *gArr, uchar *bArr){ /* for loop initalisation variables */ int h, w; /* try and grab the next frame */ if(!cvGrabFrame(capture)){ printf("Could not grab a camera frame\n"); exit(0); } img=cvRetrieveFrame(capture,0); int nchannels = img->nChannels; int step = img->widthStep; uchar *frame = ( uchar* )img->imageData; /* loop over all pixels, writing the R G and B channel uchar values * to its corresponding array */ const int R = 2; const int G = 1; const int B = 0; int pixelCount=0; for (h=0; h < height; h++){ for (w = 0; w < width; w++){ char* rgb = frame + step * h + w * 3; bArr[pixelCount] = rgb[B]; gArr[pixelCount] = rgb[G]; rArr[pixelCount] = rgb[R]; pixelCount++; } } }
QImage* Camera::retrieveFrame() { IplImage* image = cvRetrieveFrame(capture); int width = image->width; int height = image->height; int pixels = width * height; uchar* imageData = new unsigned char[4 * pixels]; for(int i = 0; i < pixels; i++) { imageData[i * 4 + 3] = 0xFF; // alpha channel } uchar* src = (uchar*)(image->imageData); uchar* srcEnd = src + (3 * pixels); uchar* dest = imageData; do { memcpy(dest, src, 3); dest += 4; src += 3; } while(src < srcEnd); QImage* result = new QImage(imageData, width, height, QImage::Format_RGB32); return result; }
void ImageGrabberStartLoop() { // Allocate the memory storage for calculations and frame data CvMemStorage* storage = cvCreateMemStorage(0); CvCapture* capture = cvCaptureFromCAM(0); // Images to capture the frame from video or camera or from file IplImage *frame = 0; IplImage *frame_copy = 0; cvNamedWindow( "result", 1 ); // If loaded succesfully, then: if( capture ) { bool breakLoop = false; // Capture from the camera. for(;;) { if (breakLoop) break; // Capture the frame and load it in IplImage if( !cvGrabFrame( capture )) break; frame = cvRetrieveFrame( capture ); // If the frame does not exist, quit the loop if( !frame ) break; // Allocate framecopy as the same size of the frame if( !frame_copy ) frame_copy = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); // Check the origin of image. If top left, copy the image frame to frame_copy. if( frame->origin == IPL_ORIGIN_TL ) cvCopy( frame, frame_copy, 0 ); // Else flip and copy the image else cvFlip( frame, frame_copy, 0 ); cvShowImage("result",frame_copy); // Wait for a while before proceeding to the next frame int key = cvWaitKey(1); switch(key) { case -1: break; default: breakLoop = true; } } } // Destroy the window previously created with filename: "result" cvDestroyWindow("result"); // Release the images, and capture memory cvReleaseCapture( &capture ); cvReleaseImage( &frame_copy ); }
int main() { int x = 0, y = 0; char Cr = 0, Cb = 0; int width = 640, height = 320; IplImage* frame = 0; CvCapture* capture = cvCaptureFromCAM(-1); cvNamedWindow("Result",0); while(1) { cvGrabFrame(capture); frame = cvRetrieveFrame(capture); IplImage* YCrCb = cvCreateImage(cvGetSize(frame),8,3); // ycrcb 변환 IplImage* Skin = cvCreateImage(cvGetSize(frame),8,1); // 피부 이진화 height = frame->height; width = frame->width; cvCvtColor(frame,YCrCb,CV_RGB2YCrCb); for(y=0; y<height;y++) { for(x=0; x<width; x++) { Cr = (char)YCrCb->imageData[y*YCrCb->widthStep+3*x+1]; Cb = (char)YCrCb->imageData[y*YCrCb->widthStep+3*x+2]; if( (77<Cr && Cr<127) && (133<Cb && Cb<173) ) { Skin->imageData[y*Skin->widthStep+x] = 0; } else { Skin->imageData[y*Skin->widthStep+x] = 255; } } } cvShowImage("Result",Skin); cvSetZero(frame); cvSetZero(YCrCb); cvSetZero(Skin); if(cvWaitKey(33)==27) break; } cvDestroyWindow("Result"); cvReleaseCapture(&capture); return 0; }
int EdgeTest::Run() { CvCapture* capture; IplImage* frame; // Initialize the capture device capture = cvCaptureFromCAM(-1); if(!capture) { ShowError("Cannot find webcam"); return -1; } cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 700); cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 700); cvSetCaptureProperty(capture, CV_CAP_PROP_CONTRAST, 0); // Create windows to display results cvNamedWindow("Capture", 1); for(;;) { // Retrive data from webcam and copy the frame to frame_mod if(!cvGrabFrame(capture)) break; frame = cvRetrieveFrame(capture); if(!frame) break; // Show image on capture screen cvFlip(frame, frame, -1); cvShowImage("Capture", frame); // Esc key if(cvWaitKey(10) >= 0) break; } cvReleaseCapture(&capture); cvDestroyWindow("EdgeTest"); cvDestroyWindow("Capture"); return 0; }
void AVIReader::readCurFrameGray(unsigned char* grayImgData) { assert(videoCap); IplImage* img = cvRetrieveFrame(videoCap); cv::Mat rawFrame(img); cv::Mat videoFrame(_h, _w, CV_8UC1, grayImgData); if(rawFrame.type() == CV_8UC1) rawFrame.copyTo(videoFrame); else cv::cvtColor(rawFrame, videoFrame, CV_RGB2GRAY); }
IplImage* CCamera::getImage() { if(cam_type_ != CAM_SEQ) { if(cam_type_ == CAM_OPENNI) { cv::Mat bgrImage; if(!video_capture_.grab()) { std::cerr << "Can not grab images." << std::endl; return NULL; } video_capture_.retrieve(bgrImage, CV_CAP_OPENNI_BGR_IMAGE); IplImage* frame = new IplImage(bgrImage); cvCopy(frame, img_input_); } else { // grab image from camera int res=cvGrabFrame (capture_); IplImage* frame = cvRetrieveFrame(capture_); assert(frame); cvCopy(frame, img_input_); } // check whether its a flea cam if(cam_type_ == CAM_FLEA) cvFlip(img_input_); // input from flea camera is upside down IplImage* t = cvCloneImage(img_input_); cvRemap(t, img_input_, img_mapx_, img_mapy_); // rectify cvReleaseImage(&t); return img_input_; } else // image sequence { std::stringstream ss; ss << m_strImgPath << "/" << /*"img" <<*/ std::setw(4) << std::setfill('0') << m_nImgIdx << "." << img_ext_; if(verbose_) std::cout << "Load image: " << ss.str() << std::endl; // Read an image from the saved image sequence IplImage* image = cvLoadImage(ss.str().c_str(), color_ ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); // Read edge image if there are edge images in the same folder. (e.g. Berkeley edges, scale space edges) // If there are no edge images, 'img_edge_' would be NULL ss.str(std::string()); ss << m_strImgPath << "/" << /*"img" <<*/ std::setw(4) << std::setfill('0') << m_nImgIdx << "bedges." << "png"; img_edge_ = cvLoadImage(ss.str().c_str(), CV_LOAD_IMAGE_GRAYSCALE); // Increase the image index m_nImgIdx++; return image; } }
int _tmain(int argc, _TCHAR* argv[]) { IplImage* pImg; //Án©úIplImage«ü°w IplImage* pImgcanny; IplImage* pImggray; cvNamedWindow( "Camera", 1 ); cvNamedWindow( "gray", 1 ); cvNamedWindow( "canny", 1 ); CvCapture *capture; int c; capture = cvCaptureFromCAM(0); if(!capture) return -1; else printf("Camera is OK! \n"); while(true){ if(cvGrabFrame(capture)){ pImg = cvRetrieveFrame(capture); pImggray = cvCreateImage( cvGetSize(pImg), IPL_DEPTH_8U, 1); pImgcanny = cvCreateImage( cvGetSize(pImg), IPL_DEPTH_8U, 1); cvCvtColor (pImg , pImggray ,CV_BGR2GRAY); cvCanny(pImggray, pImgcanny, 50, 150, 3); cvShowImage( "Camera", pImg ); cvShowImage( "gray", pImggray ); cvShowImage( "canny", pImgcanny ); } //µ¥«ÝESC«öÁä«ö¤U«hµ²§ô if(cvWaitKey(10) == 27) break; } // end of while cvWaitKey(0); cvDestroyWindow( "Camera" );//¾P·´µøµ¡ cvReleaseCapture( &capture ); return 0; }
void USBCamReader::readCurFrame(unsigned char* rgbdata, unsigned char* graydata) { assert(videoCap); IplImage* img = cvRetrieveFrame(videoCap); cv::Mat rawFrame(img); cv::Mat rgbImg(_h, _w, CV_8UC3, rgbdata); cv::cvtColor(rawFrame, rgbImg, CV_BGR2RGB); cv::Mat videoFrame(_h, _w, CV_8UC1, graydata); cv::cvtColor(rawFrame, videoFrame, CV_RGB2GRAY); }
bool OpenCVCamera::captureFrame() { bool retVal = false; if (m_capture != NULL) { if (cvGrabFrame(m_capture)) { if (getBPP() == 1) { IplImage *tmpFrame = cvRetrieveFrame(m_capture); if (m_image == NULL) { m_image = cvCreateImage(cvGetSize(tmpFrame), IPL_DEPTH_8U, 1); } cvCvtColor(tmpFrame, m_image, CV_BGR2GRAY); } else { m_image = cvRetrieveFrame(m_capture); } retVal = true; } } return retVal; }
const IplImage* ImageGrabberGetCameraImage() { // Allocate the memory storage for calculations and frame data CvMemStorage* storage = cvCreateMemStorage(0); CvCapture* capture = cvCaptureFromCAM(0); // Images to capture the frame from video or camera or from file IplImage *frame = 0; IplImage *frame_copy = 0; // If loaded succesfully, then: if( capture ) { // Capture the frame and load it in IplImage if( !cvGrabFrame( capture )) { // Release the images, and capture memory cvReleaseCapture( &capture ); return 0; } frame = cvRetrieveFrame( capture ); // If the frame does not exist, quit if( !frame ) { // Release the images, and capture memory cvReleaseCapture( &capture ); return 0; } // Allocate framecopy as the same size of the frame if( !frame_copy ) frame_copy = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); // Check the origin of image. If top left, copy the image frame to frame_copy. if( frame->origin == IPL_ORIGIN_TL ) cvCopy( frame, frame_copy, 0 ); // Else flip and copy the image else cvFlip( frame, frame_copy, 0 ); // Release the capture but not the image cvReleaseCapture( &capture ); // return final image return frame_copy; } // Release the images, and capture memory cvReleaseCapture( &capture ); cvReleaseImage( &frame_copy ); return 0; }
/* * call-seq: * retrieve -> IplImage or nil * * Gets the image grabbed with grab. */ VALUE rb_retrieve(VALUE self) { IplImage *frame = cvRetrieveFrame(CVCAPTURE(self)); if(!frame) return Qnil; VALUE image = cIplImage::new_object(cvSize(frame->width, frame->height), CV_MAKETYPE(CV_8U, frame->nChannels)); if (frame->origin == IPL_ORIGIN_TL) { cvCopy(frame, CVARR(image)); } else { cvFlip(frame, CVARR(image)); } return image; }
bool OpenCvDevice::CaptureFrame() { bool retVal = false; if (m_capture != nullptr) { if (cvGrabFrame(m_capture)) { if (GetBpp() == 1) { IplImage *tmpFrame = cvRetrieveFrame(m_capture); if (m_image == nullptr) { m_image = cvCreateImage(cvGetSize(tmpFrame), IPL_DEPTH_8U, 1); } cvCvtColor(tmpFrame, m_image, CV_BGR2GRAY); } else { m_image = cvRetrieveFrame(m_capture); } retVal = true; } } return retVal; }
int main(int argc, char** argv) { IplImage* motion = 0; CvCapture* capture = 0; if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 ); else if( argc == 2 ) capture = cvCaptureFromFile( argv[1] ); // 如果捕获到图像 if (capture) { cvNamedWindow( "Motion", 1 ); for(;;) { IplImage* image; if( !cvGrabFrame( capture )) break; image = cvRetrieveFrame( capture ); if( image ) { if( !motion ) { motion = cvCreateImage( cvSize(image->width,image->height), 8, 3 ); cvZero( motion ); // 将采集到的图像指针赋给运动图像 motion->origin = image->origin; } } // 更新运动历史图像 update_mhi(image, motion, 30); // 显示运动图像 cvShowImage( "Motion", motion ); if( cvWaitKey(10) >= 0 ) break; } cvReleaseCapture( &capture ); cvDestroyWindow( "Motion" ); } return 0; }
IplImage* objDetection::utilities::getImageFromCamera(config& conf) { if( !cvGrabFrame( conf.capture )) { std::cout<<"Camera Stopped working, Closing"<<std::endl; return NULL; } IplImage* img= cvRetrieveFrame( conf.capture ); IplImage* res= cvCreateImage(cvSize(img->width,img->height), img->depth,3); cvCopy(img,res); return res; }
bool VideoCapture::retrieve(Mat& image, int channel) { IplImage* _img = cvRetrieveFrame(cap, channel); if (!_img) { image.release(); return false; } if (_img->origin == IPL_ORIGIN_TL) { image = Mat(_img); } else { Mat temp(_img); flip(temp, image, 0); } return true; }
int main(int argc, char** argv) { IplImage* motion = 0; CvCapture* capture = 0; if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 ); else if( argc == 2 ) capture = cvCaptureFromFile( argv[1] ); if( capture ) { help(); cvNamedWindow( "Motion", 1 ); for(;;) { IplImage* image; if( !cvGrabFrame( capture )) break; image = cvRetrieveFrame( capture ); if( image ) { if( !motion ) { motion = cvCreateImage( cvSize(image->width,image->height), 8, 3 ); cvZero( motion ); motion->origin = image->origin; } } update_mhi( image, motion, 30 ); cvShowImage( "Motion", motion ); if( cvWaitKey(10) >= 0 ) break; } cvReleaseCapture( &capture ); cvDestroyWindow( "Motion" ); } else { printf("\nFailed to open camera or file\n"); help(); } return 0; }
void Video::next(int frameDrop) { #ifdef DEBUG_CALLS std::cout << "Video next called.\n"; #endif IplImage* img; do { cvGrabFrame(stream); frameDrop--; }while(frameDrop>=0); img = cvRetrieveFrame(stream); if(img) this->actualImage = img; }
/*! Grab an image direclty in the OpenCV format. \return Pointer to the image (must not be freed). \exception vpFrameGrabberException::initializationError If the initialization of the grabber was not done previously. */ IplImage* vpOpenCVGrabber::acquire() { IplImage *im; if (init==false) { close(); throw (vpFrameGrabberException(vpFrameGrabberException::initializationError, "Initialization not done") ); } cvGrabFrame(capture); im = cvRetrieveFrame(capture); return im; }
/*! Grab a color image. \param I : Acquired color image. \exception vpFrameGrabberException::initializationError If the initialization of the grabber was not done previously. */ void vpOpenCVGrabber::acquire(vpImage<vpRGBa> &I) { IplImage *im; if (init==false) { close(); throw (vpFrameGrabberException(vpFrameGrabberException::initializationError, "Initialization not done") ); } cvGrabFrame(capture); im = cvRetrieveFrame(capture); vpImageConvert::convert(im, I, flip); }
IplImage *CCamOpenCV::CaptureImage() { if (_capture) { if (cvGrabFrame(_capture)) { IplImage *cvImage = cvRetrieveFrame(_capture); if (cvImage && cvImage->width != _bitmapInfo.bmiHeader.biWidth && cvImage->height != _bitmapInfo.bmiHeader.biHeight) { InitBitmapInfo(cvImage->width, cvImage->height, cvImage->widthStep / cvImage->width); } return cvImage; } } return NULL; }