顯示具有 程式設計 標籤的文章。 顯示所有文章
顯示具有 程式設計 標籤的文章。 顯示所有文章

2021年8月31日 星期二

程式中float比大小

 float是不能用==來進行比大小的

因為在電腦中float是近似值,而非定值

也就是說1.000

可能是0.99999999999999或者1.0000000001這種等級的數值


那最好是改用>=或者<=

具體上怎麼操作

兩數相減小於一個極小值就可以



2016年4月24日 星期日

C之txt讀檔最後一行多讀一次

這個問題稍微花了我一點時間想了下
我多跑了幾個txt檔,其中一個txt檔就是會出錯

後來看了一下讀進來的資料,發現最後一筆重複讀入
這個txt跟其他的差別只在最後一行的資料後方多了一格空格
使用feof()或者eof()就會產生這個問題

後來上網看了一下
有一篇寫的算詳細,先紀錄一下
c++ ifstream 读文件 最后一行读两次

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); //正確,這樣也可

2013年7月18日 星期四

[轉]全域變量:extern/static/const區別與聯系

在討論全局變量之前我們先要明白幾個基本的概念:

1. 編譯單元(模塊):
    在IDE開發工具大行其道的今天,對於編譯的一些概念很多人已經不再清楚了,很多程序員最怕的就是處理連接錯誤(LINK ERROR), 因為它不像編譯錯誤那樣可以給出你程序錯誤的具體位置,你常常對這種錯誤感到懊惱,但是如果你經常使用gcc,makefile等工具在linux或者嵌 入式下做開發工作的話,那麼你可能非常的理解編譯與連接的區別!當在VC這樣的開發工具上編寫完代碼,點擊編譯按鈕准備生成exe文件時,VC其實做了兩 步工作,第一步,將每個.cpp(.c)和相應.h文件編譯成obj文件;第二步,將工程中所有的obj文件進行LINK生成最終的.exe文件,那麼錯 誤就有可能在兩個地方產生,一個是編譯時的錯誤,這個主要是語法錯誤,另一個是連接錯誤,主要是重復定義變量等。我們所說的編譯單元就是指在編譯階段生成 的每個obj文件,一個obj文件就是一個編譯單元,也就是說一個cpp(.c)和它相應的.h文件共同組成了一個編譯單元,一個工程由很多個編譯單元組 成,每個obj文件裡包含了變量存儲的相對地址等 。

ADGuard