1.指針的用法
1.如何打印指針變量的值?
windows:使用 Visual Studio (Graphical Interface) 編譯
2011 | C++11 | 第三個C++標準 |
-
cv::Mat imgDst = convertTo3Channels(imgSrc);
一::在C++中是什麼意思
今天又想了一下::在C++中是什麼意思;
表示作用域,和所屬關係
比如
class A
{
public: int test();
}
int A::test() //表示test是屬於A的
{
return 0;
}
類似的還有其他,就不列舉了 -------------------- 比如 int a;
void test ()
{
int a = ::a; //用全局變量a,給本地變量a賦值
}
::是運算符中等級最高的,它分爲三種: 1)global scope(全局作用域符),用法(::name) 2)class scope(類作用域符),用法(class::name) 3)namespace scope(命名空間作用域符)
============================== -
int main () { int var; int *ptr; int **pptr; var = 3000; // 獲取 var 的地址 ptr = &var; // 使用運算符 & 獲取 ptr 的地址 pptr = &ptr; // 使用 pptr 獲取值 cout << "var 值爲 :" << var << endl; cout << "*ptr 值爲:" << *ptr << endl; cout << "**pptr 值爲:" << **pptr << endl; return 0; }
二 &符號是什麼作用?Mat convertTo3Channels(const Mat &binImg)
memcpy函數
功能
memcpy指的是c和c++使用的內存拷貝函數,memcpy函數的功能是從源src所指的內存地址的起始位置開始拷貝n個字節到目標dest所指的內存地址的起始位置中
- ,函數 memcpy() 用來複制內存到另一個位置。
ReleaseFloatArrayElements和DeleteLocalRef之間有什麼區別
用完之後別忘了釋放
三.typedef代表什麼意思?
return detect_MobileNetSSD(tg_handle->net, img, rect);
struct timeval tv;
C++ 日期 & 時間
//計算時間
long getCurrentTime()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
#include <time.h>
// 聲明一個結構體類型 Books
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
};
int main( )
{
Books Book1; // 定義結構體類型 Books 的變量 Book1
Books Book2; // 定義結構體類型 Books 的變量 Book2
// Book1 詳述
strcpy( Book1.title, "C++ 教程");
strcpy( Book1.author, "Runoob");
strcpy( Book1.subject, "編程語言");
Book1.book_id = 12345;
delete handle;
typedef struct _tongue_handle
{
int magic;
ncnn::Net net;
}
tongue_handle;
TONGUE_HANDLE tongue_init(JNIEnv *env, const char *paramPath, const char *modelPath)
{
int rc = 0;
tongue_handle *handle = new tongue_handle();
基礎語法:
定義常量
在 C++ 中,有兩種簡單的定義常量的方式:
- 使用 #define 預處理器。
- 使用 const 關鍵字。
存儲類定義 C++ 程序中變量/函數的範圍(可見性)和生命週期。這些說明符放置在它們所修飾的類型之前。下面列出 C++ 程序中可用的存儲類:
- auto
- register
- static
- extern
- mutable
- thread_local (C++11)
typedef 聲明
您可以使用 typedef 爲一個已有的類型取一個新的名字。下面是使用 typedef 定義一個新類型的語法:
<span style="color:#000000"><span style="color:#333333"><span style="color:#000088">typedef</span><span style="color:#000000"> type newname</span><span style="color:#666600">;</span> </span></span>
typedef void *TONGUE_HANDLE;
用完之後別忘了釋放
- 如何把數組轉爲數組指針?
jbyte *yuv = env->GetByteArrayElements(yuvData, 0);
基本的語法:如何判斷一個指針是否爲null?if(bgr.data==NULL){ return -1; }
如何校驗一個對象爲null?C++語言中,對象沒有空和不空的概念,只有對象指針纔有空和不空的概念
判抄斷對象指針是否爲空襲只需要和NULL常量進行比較即可
如果相等,則爲空,否則不爲空
另外對象雖然沒有空和不空的概念bai,但是有有效和無效的概念const關鍵字:C++ const 允許指定一個語義約束,編譯器會強制實施這個約束,允許程序員告訴編譯器某值是保持不變的。如果在編程中確實有某個值保持不變,就應該明確使用const相當於java裏面的final修飾內容:修飾指針:C++ 字符(char)指針
char 指針可以看作是字符串, 比如說:
const char *str="HelloWorld!";
本人極不建議使用 char 指針,畢竟 std::string 可以完全替代其並且功能也比它強大,使用使用更加方便如何升級:把頭文件和.a文件都升級找到substract_mean_normalize的實現類 - 問題:如何知道你的語言是c?還是c++
- 開發大全
- https://blog.csdn.net/afei__/article/details/81290711
const char *paramPathC = env->GetStringUTFChars(paramPath, NULL);
const char *modelPathC = env->GetStringUTFChars(modelPath, NULL);
const char* GetStringUTFChars(jstring string, jboolean* isCopy)
{ return functions->GetStringUTFChars(this, string, isCopy); }
<span style="color:#000000"><span style="color:#333333"><span style="color:#000088">char</span><span style="color:#000000"> greeting</span><span style="color:#666600">[]</span> <span style="color:#666600">=</span> <span style="color:#008800">"Hello"</span><span style="color:#666600">;</span></span></span>
C++ 中的 String 類
int rc = 0;
tongue_handle *handle = new tongue_handle();
// if(NULL == handle)
// return NULL;
// rc = handle->net.load_param("./models/tongue_5classes_singlechannel.param");
rc = handle->net.load_param(paramPath);//
//��ȡ.param����ȡ�ɹ�ʱrc=0 ,�xȡ.h ��ȡ�ɹ�ʱrc!=0
if(rc != 0)
{
//"load_person_param error"
__android_log_print(ANDROID_LOG_DEBUG, "james", "load_person_param error :%d",rc);
delete handle;
return NULL;
}
typedef struct _tongue_handle
{
int magic;
ncnn::Net net;
} tongue_handle;
#ifndef __TONGUE_H__
#define __TONGUE_H__
typedef void *TONGUE_HANDLE;
TONGUE_HANDLE tongue_init(JNIEnv *env,const char *paramPath, const char *modelPath);
int tongue_uninit(TONGUE_HANDLE handle);
int tongue_detect(TONGUE_HANDLE handle, cv::Mat img, cv::Rect &box);
#endif//__TONGUE_H__
4.數組轉成int8_t
jbyte *yuv = env->GetByteArrayElements(yuvData, 0);
typedef int8_t jbyte; /* signed 8 bits */
(unsigned char *) yuv代碼轉換
cv::Mat imgSrc(height, width, CV_8UC3, (unsigned char *) yuv);
cv::Mat imgDst = convertTo3Channels(imgSrc);
using namespace cv;
using namespace std;
<span style="color:#000000"><span style="color:#333333">98年以後的c++語言提供一個全局的命名空間namespace,可以避免導致全局命名衝突問題</span></span>
因此,當使用<iostream.h>時,相當於在c中調用庫函數,使用的是全局命名空間,也就是早期的c++實現;當使用< iostream>的時候,該頭文件沒有定義全局命名空間,必須使用namespace std;這樣才能正確使用cout。#include <iostream.h>
using namespace std; 則出錯
所以 要麼寫成
#include <iostream >
using namespace std;
要麼寫成
#include <iostream.h>
當然最好是前種
TongueInfo ti;
long processImage_time_start = getCurrentTime();
int rc = processImage(imgSrc, ti);
int processImage(cv::Mat src, TongueInfo &ti)
{
//src > BGR
cv::Rect rect;
int rc;
memset(&ti, 0, sizeof(ti));//清空先前存的結果
typedef struct _TongueInfo {
bool isTongue;
float togueLocation[4];
} TongueInfo;
memset(&ti, 0, sizeof(ti));//清空先前存的結果
//計算時間
long getCurrentTime()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}