顯示具有 OpenCV 標籤的文章。 顯示所有文章
顯示具有 OpenCV 標籤的文章。 顯示所有文章

2016年7月23日 星期六

Opencv函數記憶體釋放

在看別的記憶體問題的時候看到的
mark

應該算是舊版的OpenCV才會有這個問題


http://wenku.baidu.com/view/326b7107bed5b9f3f90f1c7d.html

2016年5月28日 星期六

Opencv wmv 檔案無法讀取 播放 的 問題

Opencv讀取wmv檔案時有時候會遇到問題,通常MP4跟AVI檔案不會有問題,網路上通常是說是dll檔的問題,改個名就好。

在opencv安裝路徑下的\sources\3rdparty\ffmpeg資料夾,如C:\opencv249\sources\3rdparty\ffmpeg。

如果當初安裝設定是用32位元,則將資料夾中的opencv_ffmpeg.dll檔案名修改為opencv_ffmpeg2410.dll,如果是opencv2.4.9,則改成opencv_ffmpeg249.dll。其他版本依此類推。
如果是64位元系統,那就修改opencv_ffmpeg_64.dll檔案名為opencv_ffmpeg2410_64.dll。

並在環境變數中的系統變數進行修改,當初安裝OpenCV環境設定的時候應該有加入一個路徑的變量。參考的文章大多是用Path,我之前是另外用了LibraryPath。

如果不知道自己用哪個的話,把這個加到C:\opencv249\sources\3rdparty\ffmpeg
加到Path中,並在專案的屬性中的函式庫連結補上 $(Path)。

忘記當初設定的話,在之前專案的屬性可以找到,也可以稍微看一下系統變數,不過會隨著呼叫的libary越多,裡面寫的東西越多...不好找就是。



因為我原本命名的是LibraryPath
但到現在也忘了,看到才想到
晚點換到LibraryPath裡面,就可以省略掉Path。

目前可以成功播放了

只是覺得這個bug好像是原本寫死的dll檔的檔名寫錯了(程式內吧...
然後大概因為開源的關係,所以能夠抓出來。


參考資料: http://blog.csdn.net/heyijia0327/article/details/44034671
該文章另有python的簡單改法。

2016年5月26日 星期四

Opencv影像無法顯示

群裡的問題

假設程式碼都正確,但是影像無法顯示

因為沒有加上waitkey(數字)
數字可以填0及任意正數,0代表等代下一個指令,其他代表停頓時間

那加了為甚麼就可以停頓?
消息循環的關係

消息循环

Opencv抓取螢幕畫面

Opencv抓取螢幕畫面?
一樣群裡的問題

應該是不行,opencv只能抓取camera跟影片

抓取螢幕畫面應該要用到系統指令(我的推測

所以google了下

在 Windows 下抓取螢幕畫面的方法

另外directshow應該也可以(這邊還沒看)

open-source-directshow-screen-desktop-capture-source-filter

LIST OF AVAILABLE DIRECTSHOW SCREEN CAPTURE FILTERS


Opencv跟MFC結合

重新回到群裡練功,順便將OPENCV,IP,CV,ML重新學習

群裡提出的問題
照著做,做出來效果不對
http://jingyan.baidu.com/article/f71d60375ddd411ab641d1e3.html

基本上照著做可以做出來
不過裡面漏提了一個

將DrawPicToHDC(image, IDC_ShowImg);
中的IDC_ShowImg改成IDC_STATIC

基本這樣就可以了
不過這個版本只有最基礎的顯示,而且是針對button寫死的方法
可能可以研究一下開檔的寫法
晚點寫個新版出來

問這個問題的人交流下的過程,說希望可以研究個opencv版的小畫家...跟他討論分析是可行的,大部分都有現成的function只是呼叫跟組成一個大程式而已

2015年11月4日 星期三

cvcam.h 找不到

如果下載網路上的範例程式,應該有機會遇到這個問題

雖然我覺得很神奇的是一堆人問這個問題

cvcam.h 找不到

我從網路上找到了這個的原始檔案

自己在專案裡面新增囉

總之,不囉嗦先放上來


cvcam.h

/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                        Intel License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of Intel Corporation may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __CVCAM_H__
#define __CVCAM_H__

#if defined(_CH_)
#pragma package <opencv>
#include <chdl.h>
LOAD_CHDL_CODE(cvcam,Cvcam)
#endif

#ifdef __cplusplus
#define CVCAM_EXTERN_C extern "C" 
extern "C" {
#else
#define CVCAM_EXTERN_C
#endif /* __cplusplus */


#ifdef CVCAM_EXPORTS
#define CVCAM_API CVCAM_EXTERN_C __declspec(dllexport)
#else
#define CVCAM_API CVCAM_EXTERN_C
#endif /* CVCAM_DLLEXPORT */

/* Returns the actual number of currently available cameras */
CVCAM_API int cvcamGetCamerasCount(void);

/* get/set the property of the camera. returns 0 if the property is not supported */
CVCAM_API int cvcamGetProperty(int camera, const char* property, void* value);
CVCAM_API int cvcamSetProperty(int camera, const char* property, void* value);

/* gets all property names. the actual number of properties is returned. */
CVCAM_API int cvcamGetPropertiesList(int camera, const char** properties, int count);

CVCAM_API int cvcamBuildStereo(void); 

/* Prepares the currently enabled cameras for work */
CVCAM_API int cvcamInit(void);

/* Start the video */
CVCAM_API int cvcamStart(void);

/* Stop the video */
CVCAM_API int cvcamStop(void);

/* Pause the video; should be used for preventing data changes during frame reading 
    using "frame" and other properties */
CVCAM_API int cvcamPause(void);

/* Resume the video */
CVCAM_API int cvcamResume(void);

/* Frees all resources */
CVCAM_API int cvcamExit(void);

/*Pops up a camera(s) selection dialog
Return value - number of cameras selected (0,1 or 2);
Argument: an array of selected cameras numbers
NULL if none selected. Should be released with free() when not needed.
if NULL passed, not used.
*/
CVCAM_API int cvcamSelectCamera(int** out);

/*Plays a specified avi file into a specified window
if file is NULL, file browser is opened. if window is 0,
it is created. width and height mean output size's 0 means
those of avi file are used. __cdecl (*callback)(IplImage*) would be
called on every frame. NULL means no callback*/
CVCAM_API int cvcamPlayAVI(const char* file, 
                           void* window, 
                           int width, 
                           int height,
                           void* callback); 


/*Advanced API for dealing with AVI files*/

typedef unsigned int cvcamAVIFILE;


/*Opens a given file or pops up a dialog if file is NULL
returns a handle to the file opened for success or -1 for failure*/
CVCAM_API cvcamAVIFILE cvcamAVIOpenFile(char* file);

/*The next functions just do what they say and return 0
for success, anything other for failure*/

CVCAM_API int cvcamAVICloseFile(cvcamAVIFILE file);

CVCAM_API int cvcamAVISetWindow(cvcamAVIFILE file, void* window);

CVCAM_API int cvcamAVISetCallback(cvcamAVIFILE file, void* callback);

CVCAM_API int cvcamAVISetSize(cvcamAVIFILE file, int width, int height);

CVCAM_API int cvcamAVIRun(cvcamAVIFILE file);

CVCAM_API int cvcamAVIStop(cvcamAVIFILE file);

CVCAM_API int cvcamAVIPause(cvcamAVIFILE file);

CVCAM_API int cvcamAVIResume(cvcamAVIFILE file);

CVCAM_API int cvcamAVIWaitCompletion(cvcamAVIFILE file);

CVCAM_API int cvcamAVIIsRunning(cvcamAVIFILE file);

static const char CVCAM_PROP_ENABLE[] = "enable";
static const char CVCAM_PROP_RENDER[] = "render";
static const char CVCAM_PROP_WINDOW[] = "window";
static const char CVCAM_PROP_CALLBACK[] = "callback";
static const char CVCAM_DESCRIPTION[] = "description";
static const char CVCAM_VIDEOFORMAT[] = "video_pp";
static const char CVCAM_CAMERAPROPS[] = "camera_pp";
static const char CVCAM_RNDWIDTH[] = "rendering_width";
static const char CVCAM_RNDHEIGHT[] = "rendering_height";
static const char CVCAM_STEREO_CALLBACK[] = "stereo_callback";
static const char CVCAM_PROP_SETFORMAT[] = "set_video_format";
static const char CVCAM_PROP_RAW[] = "raw_image";
static const char CVCAM_PROP_TIME_FORMAT[] = "time_format";
static const char CVCAM_PROP_DURATION[] = "duration";
static const char CVCAM_PROP_POSITION[] = "current_position";

extern const int FRAMES_FORMAT ;
extern const int TIME_FORMAT ;

typedef struct
{
    char DeviceDescription[100];
    char device[100];
    int  channel;
    char ChannelDescription[100];
    int  maxwidth;
    int  maxheight;
    int  minwidth;
    int  minheight;
}CameraDescription;



#define CVCAMTRUE  (void*)1
#define CVCAMFALSE (void*)0

typedef int cvcamWindow;


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif //__CVCAM_H__

2014年2月21日 星期五

OpenCV永久配置方法

http://blog.csdn.net/mushiqingchang/article/details/8216111
剛好有人在問這個問題,我研究下
發現這方法挺實用的

一次改變全部屬性
當然優點是以後要用OpenCV都不用再改了

缺點就是每次的環境配置都有OpenCV在裡面

玩了一下,算實用吧

2014年1月20日 星期一

[轉] IpImage 與 cvImage, cvMat 與 cv::Mat

小飛:基本上看這篇文章獲益良多,先轉過來

Overview:總結下它們之間的不同
1. IpImage 和 cvMat 是C語言的struct。 而cvImage和cv::Mat 是c++中的結構。
2. cvImage 是 IpImage 的C++的wrapper,相當於IpImage的智能指針。cvImage 現在已經deprecated了。甚至已經被移到頭文件#include <legacy/legacy.hpp> 裡。盡管我不知道為啥deprecated,可能是應為陷阱太多的緣故把。
3. IpImage 是針對圖像來的。它的成員處理row,column以外,還有nChannel, aiphaChannel, depth 等圖像才有的信息。而cvMat和cv::Mat 針對矩陣,方便了矩陣操作,當然cv::Mat 作為c++的類,可以幫你去管理內存的分配,這樣就不用自己去create和release了,比cvMat要方便。

下面主要介紹下IpImage 和 cv::Mat 的文件IO操作以及他們之間的相互轉化
1. IpImage 的文件IO
#include
#include
#include
IplImage * src_Img = NULL;
src_Img = cvLoadImage( ".//input.jpg" , CV_LOAD_IMAGE_GRAYSCALE );
cvReleaseImage (& src_Img);

2.IpImage 轉 cvMat
cvMat好像不能直接從文件中讀取,要從IpImage轉化而來。
IplImage * src_Img = NULL;
src_Img = cvLoadImage( ".//input.jpg" , CV_LOAD_IMAGE_GRAYSCALE );
cvMat *src_mat = cvCreateMat(src_Img->height, src_Img->width);
cvConvert (src_Img , src_mat );
cvReleaseImage (& src_Img);
cvReleaseMat (&src_mat );

3. cvMat 轉 IpImage
IplImage* img = cvCreateImage(cvGetSize(mat),8,1);
cvGetImage(matI,img);
cvSaveImage("rice1.bmp",img);

4. Mat 讀取圖像
Mat mat = imread (".//input.jpg" , CV_8UC1 );

5. Mat 轉 CvMat
OpenCV 裡面很多函數例如cvZeros 等的輸入參數都是CvArr *. Mat 是不能直接轉CvArray的
Mat m = imread("input.jpg", CV_8UC1);
cvZeros(&m); // 錯誤
*****************
CvMat m1 = m; //淺拷貝, 不會復制數據,只會指向m中的數據
cvZeros(&m); //正確
********************
cvZero (&(CvMat ) mat); //正確,這樣也可

ADGuard