张洋 2 giorni fa
parent
commit
aaa4892a32

+ 86 - 0
.editorconfig

@@ -0,0 +1,86 @@
+# Visual Studio 生成了具有 C++ 设置的 .editorconfig 文件。
+root = true
+
+[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
+
+# Visual C++ 代码样式设置
+
+cpp_generate_documentation_comments = doxygen_slash_star
+
+# Visual C++ 格式设置
+
+indent_style = tab
+indent_size = 4
+tab_width= 4
+cpp_indent_braces = false
+cpp_indent_multi_line_relative_to = innermost_parenthesis
+cpp_indent_within_parentheses = indent
+cpp_indent_preserve_within_parentheses = false
+cpp_indent_case_contents = true
+cpp_indent_case_labels = true
+cpp_indent_case_contents_when_block = false
+cpp_indent_lambda_braces_when_parameter = true
+cpp_indent_goto_labels = one_left
+cpp_indent_preprocessor = leftmost_column
+cpp_indent_access_specifiers = false
+cpp_indent_namespace_contents = true
+cpp_indent_preserve_comments = false
+cpp_new_line_before_open_brace_namespace = new_line
+cpp_new_line_before_open_brace_type = new_line
+cpp_new_line_before_open_brace_function = new_line
+cpp_new_line_before_open_brace_block = new_line
+cpp_new_line_before_open_brace_lambda = new_line
+cpp_new_line_scope_braces_on_separate_lines = true
+cpp_new_line_close_brace_same_line_empty_type = false
+cpp_new_line_close_brace_same_line_empty_function = false
+cpp_new_line_before_catch = true
+cpp_new_line_before_else = true
+cpp_new_line_before_while_in_do_while = false
+cpp_space_before_function_open_parenthesis = remove
+cpp_space_within_parameter_list_parentheses = false
+cpp_space_between_empty_parameter_list_parentheses = false
+cpp_space_after_keywords_in_control_flow_statements = true
+cpp_space_within_control_flow_statement_parentheses = false
+cpp_space_before_lambda_open_parenthesis = false
+cpp_space_within_cast_parentheses = false
+cpp_space_after_cast_close_parenthesis = false
+cpp_space_within_expression_parentheses = false
+cpp_space_before_block_open_brace = true
+cpp_space_between_empty_braces = false
+cpp_space_before_initializer_list_open_brace = false
+cpp_space_within_initializer_list_braces = true
+cpp_space_preserve_in_initializer_list = true
+cpp_space_before_open_square_bracket = false
+cpp_space_within_square_brackets = false
+cpp_space_before_empty_square_brackets = false
+cpp_space_between_empty_square_brackets = false
+cpp_space_group_square_brackets = true
+cpp_space_within_lambda_brackets = false
+cpp_space_between_empty_lambda_brackets = false
+cpp_space_before_comma = false
+cpp_space_after_comma = true
+cpp_space_remove_around_member_operators = true
+cpp_space_before_inheritance_colon = true
+cpp_space_before_constructor_colon = true
+cpp_space_remove_before_semicolon = true
+cpp_space_after_semicolon = true
+cpp_space_remove_around_unary_operator = true
+cpp_space_around_binary_operator = insert
+cpp_space_around_assignment_operator = insert
+cpp_space_pointer_reference_alignment = left
+cpp_space_around_ternary_operator = insert
+cpp_use_unreal_engine_macro_formatting = true
+cpp_wrap_preserve_blocks = never
+
+# Visual C++ include 清理设置
+
+cpp_include_cleanup_add_missing_error_tag_type = none
+cpp_include_cleanup_remove_unused_error_tag_type = none
+cpp_include_cleanup_optimize_unused_error_tag_type = none
+cpp_include_cleanup_sort_after_edits = false
+cpp_include_cleanup_format_after_edits = false
+cpp_sort_includes_error_tag_type = none
+cpp_sort_includes_priority_case_sensitive = false
+cpp_sort_includes_priority_style = quoted
+cpp_includes_style = default
+cpp_includes_use_forward_slash = true

+ 31 - 3
zhipuzi_pos_windows/worker/CVideoCaptureWorker.cpp

@@ -77,20 +77,22 @@ void CVideoCaptureWorker::HandleVideoCapture()
 
     while (m_is_work == true)
     {
-		//m_worker_mutex.lock();
+		m_worker_mutex.lock();
 
         // 读取摄像头帧
         cap >> m_frame;
         if (m_frame.empty())
         {
-			//m_worker_mutex.unlock();
+            m_worker_mutex.unlock();
 
             DEBUG_LOG("读取摄像头帧失败,正在重试...");
             CSystem::my_sleep(1);
             continue;
         }
 
-        //m_worker_mutex.unlock();
+        m_worker_mutex.unlock();
+
+		Sleep(20);
 
 		//什么都不用做,只需要把摄像头读取的帧放在成员变量里就行,后续其他地方需要用到摄像头数据的时候直接从成员变量里取就行了
         // 显示摄像头帧(可选)
@@ -103,4 +105,30 @@ void CVideoCaptureWorker::HandleVideoCapture()
     cv::destroyAllWindows();
 
     return;
+}
+
+void CVideoCaptureWorker::GetFrame(cv::Mat& frame)
+{
+	auto time_1 = std::chrono::high_resolution_clock::now();
+
+	m_worker_mutex.lock();
+
+	auto time_2 = std::chrono::high_resolution_clock::now();
+
+    frame = m_frame.clone();
+
+	m_worker_mutex.unlock();
+
+	auto time_3 = std::chrono::high_resolution_clock::now();
+
+
+	auto duration_1 = std::chrono::duration_cast<std::chrono::milliseconds>(time_2 - time_1);
+	std::wstring msg = L"获得锁耗时: " + std::to_wstring(duration_1.count()) + L" 毫秒";
+	DEBUG_LOG(msg.c_str());
+
+	auto duration_2 = std::chrono::duration_cast<std::chrono::milliseconds>(time_3 - time_2);
+	std::wstring msg2 = L"复制数据耗时: " + std::to_wstring(duration_2.count()) + L" 毫秒";
+	DEBUG_LOG(msg2.c_str());
+
+	int a = 1;
 }

+ 1 - 4
zhipuzi_pos_windows/worker/CVideoCaptureWorker.h

@@ -22,10 +22,7 @@ public:
 
 	void HandleVideoCapture();
 
-	void GetFrame(cv::Mat& frame)
-	{
-		frame = m_frame.clone();
-	}
+	void GetFrame(cv::Mat& frame);
 
 	int findAvailableCamera();