mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge branch 'code_formatting' of https://github.com/jainanshul/node-opencv into jainanshul-code_formatting
This commit is contained in:
commit
6363918463
267
js_code_style.xml
Executable file
267
js_code_style.xml
Executable file
@ -0,0 +1,267 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<profiles version="11">
|
||||
<profile kind="CodeFormatterProfile" name=“opencv” version="11">
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_empty_lines" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_after_annotation" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.format_header" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.format_block_comments" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_colon_in_object_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_between_type_declarations" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.tabulation.size" value="2"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.continuation_indentation_for_objlit_initializer" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.compiler.compliance" value="1.5"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_before_closing_brace_in_objlit_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.format_source_code" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_after_comma_in_objlit_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.format_javadoc_comments" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indentation.size" value="2"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_objlit_initializer" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.compiler.source" value="1.5"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.continuation_indentation" value="2"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.lineSplit" value="80"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.format_html" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.compiler.codegen.targetPlatform" value="1.5"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.keep_empty_objlit_initializer_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_colon_in_object_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.line_length" value="80"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.tabulation.char" value="space"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_after_opening_brace_in_objlit_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.compact_else_if" value="true"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.wst.jsdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||
</profile>
|
||||
</profiles>
|
||||
166
native_code_style.xml
Executable file
166
native_code_style.xml
Executable file
@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<profiles version="1">
|
||||
<profile kind="CodeFormatterProfile" name=“opencv” version="1">
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.lineSplit" value="80"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_member_access" value="0"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_constructor_initializer_list" value="51"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.comment.min_distance_between_code_and_line_comment" value="2"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.tabulation.size" value="2"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_enumerator_list" value="48"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_declarator_list" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_empty_lines" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.join_wrapped_lines" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.continuation_indentation" value="2"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_expression_list" value="0"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_conditional_expression" value="34"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_access_specifier_extra_spaces" value="0"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_assignment" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_conditional_expression_chain" value="18"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration" value="80"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.tabulation.char" value="space"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_colon_in_constructor_initializer_list" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.compact_else_if" value="true"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.alignment_for_overloaded_left_shift_chain" value="16"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.indentation.size" value="2"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments" value="do not insert"/>
|
||||
</profile>
|
||||
</profiles>
|
||||
@ -3,37 +3,35 @@
|
||||
#include <iostream>
|
||||
#include <nan.h>
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
Persistent<FunctionTemplate> BackgroundSubtractorWrap::constructor;
|
||||
|
||||
void
|
||||
BackgroundSubtractorWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void BackgroundSubtractorWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(BackgroundSubtractorWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("BackgroundSubtractor"));
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(BackgroundSubtractorWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("BackgroundSubtractor"));
|
||||
|
||||
NODE_SET_METHOD(ctor, "createMOG", CreateMOG);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "applyMOG", ApplyMOG);
|
||||
NODE_SET_METHOD(ctor, "createMOG", CreateMOG);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "applyMOG", ApplyMOG);
|
||||
|
||||
target->Set(NanNew("BackgroundSubtractor"), ctor->GetFunction());
|
||||
|
||||
};
|
||||
target->Set(NanNew("BackgroundSubtractor"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(BackgroundSubtractorWrap::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
//Create MOG by default
|
||||
// Create MOG by default
|
||||
cv::Ptr<cv::BackgroundSubtractor> bg;
|
||||
BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap(bg);
|
||||
|
||||
pt->Wrap(args.This());
|
||||
|
||||
NanReturnValue(args.This());
|
||||
@ -61,45 +59,39 @@ NAN_METHOD(BackgroundSubtractorWrap::CreateMOG) {
|
||||
|
||||
pt->Wrap(n);
|
||||
NanReturnValue( n );
|
||||
};
|
||||
}
|
||||
|
||||
//Fetch foreground mask
|
||||
// Fetch foreground mask
|
||||
NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
|
||||
|
||||
SETUP_FUNCTION(BackgroundSubtractorWrap)
|
||||
|
||||
SETUP_FUNCTION(BackgroundSubtractorWrap);
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
Local<Value> argv[2];
|
||||
|
||||
if(args.Length() == 0){
|
||||
if (args.Length() == 0) {
|
||||
argv[0] = NanNew("Input image missing");
|
||||
argv[1] = NanNull();
|
||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
Local<Object> fgMask = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
try {
|
||||
Local<Object> fgMask =
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(fgMask);
|
||||
|
||||
|
||||
cv::Mat mat;
|
||||
|
||||
if(Buffer::HasInstance(args[0])){
|
||||
if (Buffer::HasInstance(args[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||
unsigned len = Buffer::Length(args[0]->ToObject());
|
||||
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
|
||||
mat = cv::imdecode(*mbuf, -1);
|
||||
//mbuf->release();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
Matrix *_img = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
mat = (_img->mat).clone();
|
||||
}
|
||||
|
||||
if (mat.empty()){
|
||||
if (mat.empty()) {
|
||||
return NanThrowTypeError("Error loading file");
|
||||
}
|
||||
|
||||
@ -107,33 +99,29 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
|
||||
self->subtractor->operator()(mat, _fgMask);
|
||||
|
||||
img->mat = _fgMask;
|
||||
|
||||
mat.release();
|
||||
|
||||
argv[0] = NanNull();
|
||||
argv[1] = fgMask;
|
||||
|
||||
TryCatch try_catch;
|
||||
|
||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
}
|
||||
|
||||
NanReturnUndefined();
|
||||
}
|
||||
catch( cv::Exception& e ){
|
||||
FatalException(try_catch);
|
||||
}
|
||||
NanReturnUndefined();
|
||||
} catch (cv::Exception& e) {
|
||||
const char* err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BackgroundSubtractorWrap::BackgroundSubtractorWrap(cv::Ptr<cv::BackgroundSubtractor> _subtractor){
|
||||
BackgroundSubtractorWrap::BackgroundSubtractorWrap(
|
||||
cv::Ptr<cv::BackgroundSubtractor> _subtractor) {
|
||||
subtractor = _subtractor;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
#include <opencv2/video/background_segm.hpp>
|
||||
|
||||
class BackgroundSubtractorWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::Ptr<cv::BackgroundSubtractor> subtractor;
|
||||
public:
|
||||
cv::Ptr<cv::BackgroundSubtractor> subtractor;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
BackgroundSubtractorWrap(cv::Ptr<cv::BackgroundSubtractor> bg);
|
||||
BackgroundSubtractorWrap(cv::Ptr<cv::BackgroundSubtractor> bg);
|
||||
|
||||
static NAN_METHOD(CreateMOG);
|
||||
static NAN_METHOD(ApplyMOG);
|
||||
static NAN_METHOD(CreateMOG);
|
||||
static NAN_METHOD(ApplyMOG);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
833
src/Calib3D.cc
833
src/Calib3D.cc
@ -1,589 +1,560 @@
|
||||
#include "Calib3D.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
inline Local<Object> matrixFromMat(cv::Mat &input)
|
||||
{
|
||||
Local<Object> matrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *matrix = ObjectWrap::Unwrap<Matrix>(matrixWrap);
|
||||
matrix->mat = input;
|
||||
inline Local<Object> matrixFromMat(cv::Mat &input) {
|
||||
Local<Object> matrixWrap =
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *matrix = ObjectWrap::Unwrap<Matrix>(matrixWrap);
|
||||
matrix->mat = input;
|
||||
|
||||
return matrixWrap;
|
||||
return matrixWrap;
|
||||
}
|
||||
|
||||
inline cv::Mat matFromMatrix(Handle<Value> matrix)
|
||||
{
|
||||
Matrix* m = ObjectWrap::Unwrap<Matrix>(matrix->ToObject());
|
||||
return m->mat;
|
||||
inline cv::Mat matFromMatrix(Handle<Value> matrix) {
|
||||
Matrix* m = ObjectWrap::Unwrap<Matrix>(matrix->ToObject());
|
||||
return m->mat;
|
||||
}
|
||||
|
||||
inline cv::Size sizeFromArray(Handle<Value> jsArray)
|
||||
{
|
||||
cv::Size patternSize;
|
||||
inline cv::Size sizeFromArray(Handle<Value> jsArray) {
|
||||
cv::Size patternSize;
|
||||
|
||||
if (jsArray->IsArray())
|
||||
{
|
||||
Local<Object> v8sz = jsArray->ToObject();
|
||||
if (jsArray->IsArray()) {
|
||||
Local<Object> v8sz = jsArray->ToObject();
|
||||
|
||||
patternSize = cv::Size(v8sz->Get(0)->IntegerValue(), v8sz->Get(1)->IntegerValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
JSTHROW_TYPE("Size is not a valid array");
|
||||
}
|
||||
patternSize = cv::Size(v8sz->Get(0)->IntegerValue(),
|
||||
v8sz->Get(1)->IntegerValue());
|
||||
} else {
|
||||
JSTHROW_TYPE("Size is not a valid array");
|
||||
}
|
||||
|
||||
return patternSize;
|
||||
return patternSize;
|
||||
}
|
||||
|
||||
inline std::vector<cv::Point2f> points2fFromArray(Handle<Value> array)
|
||||
{
|
||||
std::vector<cv::Point2f> points;
|
||||
if(array->IsArray())
|
||||
{
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
inline std::vector<cv::Point2f> points2fFromArray(Handle<Value> array) {
|
||||
std::vector<cv::Point2f> points;
|
||||
if (array->IsArray()) {
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
|
||||
for(unsigned int i = 0; i < pointsArray->Length(); i++)
|
||||
{
|
||||
Local<Object> pt = pointsArray->Get(i)->ToObject();
|
||||
points.push_back(cv::Point2f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JSTHROW_TYPE("Points not a valid array");
|
||||
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
|
||||
Local<Object> pt = pointsArray->Get(i)->ToObject();
|
||||
points.push_back(
|
||||
cv::Point2f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value()));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Points not a valid array");
|
||||
}
|
||||
|
||||
return points;
|
||||
return points;
|
||||
}
|
||||
|
||||
inline std::vector<cv::Point3f> points3fFromArray(Handle<Value> array)
|
||||
{
|
||||
std::vector<cv::Point3f> points;
|
||||
if(array->IsArray()) {
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
inline std::vector<cv::Point3f> points3fFromArray(Handle<Value> array) {
|
||||
std::vector<cv::Point3f> points;
|
||||
if (array->IsArray()) {
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
|
||||
for(unsigned int i = 0; i < pointsArray->Length(); i++)
|
||||
{
|
||||
Local<Object> pt = pointsArray->Get(i)->ToObject();
|
||||
points.push_back(cv::Point3f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("z"))->ToNumber()->Value()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
|
||||
Local<Object> pt = pointsArray->Get(i)->ToObject();
|
||||
points.push_back(
|
||||
cv::Point3f(pt->Get(NanNew<String>("x"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("y"))->ToNumber()->Value(),
|
||||
pt->Get(NanNew<String>("z"))->ToNumber()->Value()));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
}
|
||||
|
||||
return points;
|
||||
return points;
|
||||
}
|
||||
|
||||
inline std::vector<std::vector<cv::Point2f> > points2fFromArrayOfArrays(Handle<Value> array)
|
||||
{
|
||||
std::vector<std::vector<cv::Point2f> > points;
|
||||
if(array->IsArray())
|
||||
{
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
inline std::vector<std::vector<cv::Point2f> > points2fFromArrayOfArrays(
|
||||
Handle<Value> array) {
|
||||
std::vector<std::vector<cv::Point2f> > points;
|
||||
if (array->IsArray()) {
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
|
||||
for(unsigned int i = 0; i < pointsArray->Length(); i++)
|
||||
{
|
||||
points.push_back(points2fFromArray(pointsArray->Get(i)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
|
||||
points.push_back(points2fFromArray(pointsArray->Get(i)));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
}
|
||||
|
||||
return points;
|
||||
return points;
|
||||
}
|
||||
|
||||
inline std::vector<std::vector<cv::Point3f> > points3fFromArrayOfArrays(Handle<Value> array)
|
||||
{
|
||||
std::vector<std::vector<cv::Point3f> > points;
|
||||
if(array->IsArray())
|
||||
{
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
inline std::vector<std::vector<cv::Point3f> > points3fFromArrayOfArrays(
|
||||
Handle<Value> array) {
|
||||
std::vector<std::vector<cv::Point3f> > points;
|
||||
if (array->IsArray()) {
|
||||
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
|
||||
|
||||
for(unsigned int i = 0; i < pointsArray->Length(); i++)
|
||||
{
|
||||
points.push_back(points3fFromArray(pointsArray->Get(i)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
|
||||
points.push_back(points3fFromArray(pointsArray->Get(i)));
|
||||
}
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass array of object points for each frame")
|
||||
}
|
||||
|
||||
return points;
|
||||
return points;
|
||||
}
|
||||
|
||||
void Calib3D::Init(Handle<Object> target)
|
||||
{
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
void Calib3D::Init(Handle<Object> target) {
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
NODE_SET_METHOD(obj, "findChessboardCorners", FindChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "drawChessboardCorners", DrawChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "calibrateCamera", CalibrateCamera);
|
||||
NODE_SET_METHOD(obj, "solvePnP", SolvePnP);
|
||||
NODE_SET_METHOD(obj, "getOptimalNewCameraMatrix", GetOptimalNewCameraMatrix);
|
||||
NODE_SET_METHOD(obj, "stereoCalibrate", StereoCalibrate);
|
||||
NODE_SET_METHOD(obj, "stereoRectify", StereoRectify);
|
||||
NODE_SET_METHOD(obj, "computeCorrespondEpilines", ComputeCorrespondEpilines);
|
||||
NODE_SET_METHOD(obj, "reprojectImageTo3d", ReprojectImageTo3D);
|
||||
NODE_SET_METHOD(obj, "findChessboardCorners", FindChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "drawChessboardCorners", DrawChessboardCorners);
|
||||
NODE_SET_METHOD(obj, "calibrateCamera", CalibrateCamera);
|
||||
NODE_SET_METHOD(obj, "solvePnP", SolvePnP);
|
||||
NODE_SET_METHOD(obj, "getOptimalNewCameraMatrix", GetOptimalNewCameraMatrix);
|
||||
NODE_SET_METHOD(obj, "stereoCalibrate", StereoCalibrate);
|
||||
NODE_SET_METHOD(obj, "stereoRectify", StereoRectify);
|
||||
NODE_SET_METHOD(obj, "computeCorrespondEpilines", ComputeCorrespondEpilines);
|
||||
NODE_SET_METHOD(obj, "reprojectImageTo3d", ReprojectImageTo3D);
|
||||
|
||||
target->Set(NanNew("calib3d"), obj);
|
||||
target->Set(NanNew("calib3d"), obj);
|
||||
}
|
||||
|
||||
// cv::findChessboardCorners
|
||||
NAN_METHOD(Calib3D::FindChessboardCorners)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::FindChessboardCorners) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments from javascript
|
||||
try {
|
||||
// Get the arguments from javascript
|
||||
|
||||
// Arg 0 is the image
|
||||
cv::Mat mat = matFromMatrix(args[0]);
|
||||
// Arg 0 is the image
|
||||
cv::Mat mat = matFromMatrix(args[0]);
|
||||
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize = sizeFromArray(args[1]);
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize = sizeFromArray(args[1]);
|
||||
|
||||
// Arg 2 would normally be the flags, ignoring this for now and using the default flags
|
||||
// Arg 2 would normally be the flags, ignoring this for now and using the
|
||||
// default flags
|
||||
|
||||
// Find the corners
|
||||
std::vector<cv::Point2f> corners;
|
||||
bool found = cv::findChessboardCorners(mat, patternSize, corners);
|
||||
// Find the corners
|
||||
std::vector<cv::Point2f> corners;
|
||||
bool found = cv::findChessboardCorners(mat, patternSize, corners);
|
||||
|
||||
// Make the return value
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
ret->Set(NanNew<String>("found"), NanNew<Boolean>(found));
|
||||
// Make the return value
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
ret->Set(NanNew<String>("found"), NanNew<Boolean>(found));
|
||||
|
||||
Local<Array> cornersArray = NanNew<Array>(corners.size());
|
||||
for(unsigned int i = 0; i < corners.size(); i++)
|
||||
{
|
||||
Local<Object> point_data = NanNew<Object>();
|
||||
point_data->Set(NanNew<String>("x"), NanNew<Number>(corners[i].x));
|
||||
point_data->Set(NanNew<String>("y"), NanNew<Number>(corners[i].y));
|
||||
Local<Array> cornersArray = NanNew<Array>(corners.size());
|
||||
for (unsigned int i = 0; i < corners.size(); i++) {
|
||||
Local<Object> point_data = NanNew<Object>();
|
||||
point_data->Set(NanNew<String>("x"), NanNew<Number>(corners[i].x));
|
||||
point_data->Set(NanNew<String>("y"), NanNew<Number>(corners[i].y));
|
||||
|
||||
cornersArray->Set(NanNew<Number>(i), point_data);
|
||||
}
|
||||
|
||||
ret->Set(NanNew<String>("corners"), cornersArray);
|
||||
|
||||
NanReturnValue(ret);
|
||||
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
cornersArray->Set(NanNew<Number>(i), point_data);
|
||||
}
|
||||
|
||||
};
|
||||
ret->Set(NanNew<String>("corners"), cornersArray);
|
||||
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::drawChessboardCorners
|
||||
NAN_METHOD(Calib3D::DrawChessboardCorners)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::DrawChessboardCorners) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
cv::Mat mat = matFromMatrix(args[0]);
|
||||
// Arg 0 is the image
|
||||
cv::Mat mat = matFromMatrix(args[0]);
|
||||
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize = sizeFromArray(args[1]);
|
||||
// Arg 1 is the pattern size
|
||||
cv::Size patternSize = sizeFromArray(args[1]);
|
||||
|
||||
// Arg 2 is the corners array
|
||||
std::vector<cv::Point2f> corners = points2fFromArray(args[2]);
|
||||
// Arg 2 is the corners array
|
||||
std::vector<cv::Point2f> corners = points2fFromArray(args[2]);
|
||||
|
||||
// Arg 3, pattern found boolean
|
||||
bool patternWasFound = args[3]->ToBoolean()->Value();
|
||||
// Arg 3, pattern found boolean
|
||||
bool patternWasFound = args[3]->ToBoolean()->Value();
|
||||
|
||||
// Draw the corners
|
||||
cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound);
|
||||
// Draw the corners
|
||||
cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound);
|
||||
|
||||
// Return the passed image, now with corners drawn on it
|
||||
NanReturnValue(args[0]);
|
||||
// Return the passed image, now with corners drawn on it
|
||||
NanReturnValue(args[0]);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::calibrateCamera
|
||||
NAN_METHOD(Calib3D::CalibrateCamera)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::CalibrateCamera) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the array of object points, an array of arrays
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints = points3fFromArrayOfArrays(args[0]);
|
||||
// Arg 0, the array of object points, an array of arrays
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints =
|
||||
points3fFromArrayOfArrays(args[0]);
|
||||
|
||||
// Arg 1, the image points, another array of arrays
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints = points2fFromArrayOfArrays(args[1]);
|
||||
// Arg 1, the image points, another array of arrays
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints =
|
||||
points2fFromArrayOfArrays(args[1]);
|
||||
|
||||
// Arg 2, the image size
|
||||
cv::Size imageSize = sizeFromArray(args[2]);
|
||||
// Arg 2, the image size
|
||||
cv::Size imageSize = sizeFromArray(args[2]);
|
||||
|
||||
// Arg 3, 4, input guesses for the camrea matrix and distortion coefficients, skipping for now
|
||||
cv::Mat K, dist;
|
||||
// Arg 3, 4, input guesses for the camrea matrix and distortion coefficients,
|
||||
// skipping for now
|
||||
cv::Mat K, dist;
|
||||
|
||||
// Arg 5, 6 flags and termination criteria, skipping for now
|
||||
// Arg 5, 6 flags and termination criteria, skipping for now
|
||||
|
||||
// Calibrate the camera
|
||||
std::vector<cv::Mat> rvecs, tvecs;
|
||||
// Calibrate the camera
|
||||
std::vector<cv::Mat> rvecs, tvecs;
|
||||
|
||||
double error = cv::calibrateCamera(objectPoints, imagePoints, imageSize, K, dist, rvecs, tvecs);
|
||||
double error = cv::calibrateCamera(objectPoints, imagePoints, imageSize, K,
|
||||
dist, rvecs, tvecs);
|
||||
|
||||
// make the return values
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
// make the return values
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// Reprojection error
|
||||
ret->Set(NanNew<String>("reprojectionError"), NanNew<Number>(error));
|
||||
// Reprojection error
|
||||
ret->Set(NanNew<String>("reprojectionError"), NanNew<Number>(error));
|
||||
|
||||
// K
|
||||
Local<Object> KMatrixWrap = matrixFromMat(K);
|
||||
ret->Set(NanNew<String>("K"), KMatrixWrap);
|
||||
// K
|
||||
Local<Object> KMatrixWrap = matrixFromMat(K);
|
||||
ret->Set(NanNew<String>("K"), KMatrixWrap);
|
||||
|
||||
// dist
|
||||
Local<Object> distMatrixWrap = matrixFromMat(dist);
|
||||
ret->Set(NanNew<String>("distortion"), distMatrixWrap);
|
||||
// dist
|
||||
Local<Object> distMatrixWrap = matrixFromMat(dist);
|
||||
ret->Set(NanNew<String>("distortion"), distMatrixWrap);
|
||||
|
||||
// Per frame R and t, skiping for now
|
||||
// Per frame R and t, skiping for now
|
||||
|
||||
// Return
|
||||
NanReturnValue(ret);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
// Return
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::solvePnP
|
||||
NAN_METHOD(Calib3D::SolvePnP)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::SolvePnP) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the array of object points
|
||||
std::vector<cv::Point3f> objectPoints = points3fFromArray(args[0]);
|
||||
// Arg 0, the array of object points
|
||||
std::vector<cv::Point3f> objectPoints = points3fFromArray(args[0]);
|
||||
|
||||
// Arg 1, the image points
|
||||
std::vector<cv::Point2f> imagePoints = points2fFromArray(args[1]);
|
||||
// Arg 1, the image points
|
||||
std::vector<cv::Point2f> imagePoints = points2fFromArray(args[1]);
|
||||
|
||||
// Arg 2, the camera matrix
|
||||
cv::Mat K = matFromMatrix(args[2]);
|
||||
// Arg 2, the camera matrix
|
||||
cv::Mat K = matFromMatrix(args[2]);
|
||||
|
||||
// Arg 3, the distortion coefficients
|
||||
cv::Mat dist = matFromMatrix(args[3]);
|
||||
// Arg 3, the distortion coefficients
|
||||
cv::Mat dist = matFromMatrix(args[3]);
|
||||
|
||||
// Arg 4, use extrinsic guess, skipped for now
|
||||
// Arg 4, use extrinsic guess, skipped for now
|
||||
|
||||
// Arg 5, flags, skip for now
|
||||
// Arg 5, flags, skip for now
|
||||
|
||||
// solve for r and t
|
||||
cv::Mat rvec, tvec;
|
||||
// solve for r and t
|
||||
cv::Mat rvec, tvec;
|
||||
|
||||
cv::solvePnP(objectPoints, imagePoints, K, dist, rvec, tvec);
|
||||
cv::solvePnP(objectPoints, imagePoints, K, dist, rvec, tvec);
|
||||
|
||||
// make the return values
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
// make the return values
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// rvec
|
||||
Local<Object> rMatrixWrap = matrixFromMat(rvec);
|
||||
ret->Set(NanNew<String>("rvec"), rMatrixWrap);
|
||||
// rvec
|
||||
Local<Object> rMatrixWrap = matrixFromMat(rvec);
|
||||
ret->Set(NanNew<String>("rvec"), rMatrixWrap);
|
||||
|
||||
// tvec
|
||||
Local<Object> tMatrixWrap = matrixFromMat(tvec);
|
||||
ret->Set(NanNew<String>("tvec"), tMatrixWrap);
|
||||
// tvec
|
||||
Local<Object> tMatrixWrap = matrixFromMat(tvec);
|
||||
ret->Set(NanNew<String>("tvec"), tMatrixWrap);
|
||||
|
||||
// Return
|
||||
NanReturnValue(ret);
|
||||
// Return
|
||||
NanReturnValue(ret);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::getOptimalNewCameraMAtrix
|
||||
NAN_METHOD(Calib3D::GetOptimalNewCameraMatrix)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::GetOptimalNewCameraMatrix) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the original camera matrix
|
||||
cv::Mat Kin = matFromMatrix(args[0]);
|
||||
// Arg 0 is the original camera matrix
|
||||
cv::Mat Kin = matFromMatrix(args[0]);
|
||||
|
||||
// Arg 1 is the distortion coefficients
|
||||
cv::Mat dist = matFromMatrix(args[1]);
|
||||
// Arg 1 is the distortion coefficients
|
||||
cv::Mat dist = matFromMatrix(args[1]);
|
||||
|
||||
// Arg 2, the image size
|
||||
cv::Size imageSize = sizeFromArray(args[2]);
|
||||
// Arg 2, the image size
|
||||
cv::Size imageSize = sizeFromArray(args[2]);
|
||||
|
||||
// Arg 3 is the alpha free scaling parameter
|
||||
double alpha = args[3]->ToNumber()->Value();
|
||||
// Arg 3 is the alpha free scaling parameter
|
||||
double alpha = args[3]->ToNumber()->Value();
|
||||
|
||||
// Arg 4, the new image size
|
||||
cv::Size newImageSize = sizeFromArray(args[4]);
|
||||
// Arg 4, the new image size
|
||||
cv::Size newImageSize = sizeFromArray(args[4]);
|
||||
|
||||
// Arg 5, valid ROI, skip for now
|
||||
// Arg 6, center principal point, skip for now
|
||||
// Arg 5, valid ROI, skip for now
|
||||
// Arg 6, center principal point, skip for now
|
||||
|
||||
// Get the optimal new camera matrix
|
||||
cv::Mat Kout = cv::getOptimalNewCameraMatrix(Kin, dist, imageSize, alpha, newImageSize);
|
||||
// Get the optimal new camera matrix
|
||||
cv::Mat Kout = cv::getOptimalNewCameraMatrix(Kin, dist, imageSize, alpha,
|
||||
newImageSize);
|
||||
|
||||
// Wrap the output K
|
||||
Local<Object> KMatrixWrap = matrixFromMat(Kout);
|
||||
// Wrap the output K
|
||||
Local<Object> KMatrixWrap = matrixFromMat(Kout);
|
||||
|
||||
// Return the new K matrix
|
||||
NanReturnValue(KMatrixWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
// Return the new K matrix
|
||||
NanReturnValue(KMatrixWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::stereoCalibrate
|
||||
NAN_METHOD(Calib3D::StereoCalibrate)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::StereoCalibrate) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the array of object points, an array of arrays
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints = points3fFromArrayOfArrays(args[0]);
|
||||
// Arg 0, the array of object points, an array of arrays
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints =
|
||||
points3fFromArrayOfArrays(args[0]);
|
||||
|
||||
// Arg 1, the image points1, another array of arrays
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints1 = points2fFromArrayOfArrays(args[1]);
|
||||
// Arg 1, the image points1, another array of arrays
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints1 =
|
||||
points2fFromArrayOfArrays(args[1]);
|
||||
|
||||
// Arg 2, the image points2, another array of arrays =(
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints2 = points2fFromArrayOfArrays(args[2]);
|
||||
// Arg 2, the image points2, another array of arrays =(
|
||||
std::vector<std::vector<cv::Point2f> > imagePoints2 =
|
||||
points2fFromArrayOfArrays(args[2]);
|
||||
|
||||
// Arg 3 is the image size (follows the PYTHON api not the C++ api since all following arguments are optional or outputs)
|
||||
cv::Size imageSize = sizeFromArray(args[3]);
|
||||
// Arg 3 is the image size (follows the PYTHON api not the C++ api since all
|
||||
// following arguments are optional or outputs)
|
||||
cv::Size imageSize = sizeFromArray(args[3]);
|
||||
|
||||
// Arg 4,5,6,7 is the camera matrix and distortion coefficients (optional but must pass all 4 or none)
|
||||
cv::Mat k1, d1, k2, d2;
|
||||
if(args.Length() >= 8)
|
||||
{
|
||||
k1 = matFromMatrix(args[4]);
|
||||
d1 = matFromMatrix(args[5]);
|
||||
// Arg 4,5,6,7 is the camera matrix and distortion coefficients
|
||||
// (optional but must pass all 4 or none)
|
||||
cv::Mat k1, d1, k2, d2;
|
||||
if (args.Length() >= 8) {
|
||||
k1 = matFromMatrix(args[4]);
|
||||
d1 = matFromMatrix(args[5]);
|
||||
|
||||
k2 = matFromMatrix(args[6]);
|
||||
d2 = matFromMatrix(args[7]);
|
||||
}
|
||||
|
||||
// Last argument is flags, skipping for now
|
||||
|
||||
// Output mats
|
||||
cv::Mat R, t, E, F;
|
||||
|
||||
// Do the stereo calibration
|
||||
cv::stereoCalibrate(objectPoints, imagePoints1, imagePoints2, k1, d1, k2, d2, imageSize, R, t, E, F);
|
||||
|
||||
// make the return value
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// Make the output arguments
|
||||
|
||||
// k1
|
||||
Local<Object> K1MatrixWrap = matrixFromMat(k1);
|
||||
|
||||
// d1
|
||||
Local<Object> d1MatrixWrap = matrixFromMat(d1);
|
||||
|
||||
// k2
|
||||
Local<Object> K2MatrixWrap = matrixFromMat(k2);
|
||||
|
||||
// d2
|
||||
Local<Object> d2MatrixWrap = matrixFromMat(d2);
|
||||
|
||||
// R
|
||||
Local<Object> RMatrixWrap = matrixFromMat(R);
|
||||
|
||||
// t
|
||||
Local<Object> tMatrixWrap = matrixFromMat(t);
|
||||
|
||||
// E
|
||||
Local<Object> EMatrixWrap = matrixFromMat(E);
|
||||
|
||||
// F
|
||||
Local<Object> FMatrixWrap = matrixFromMat(F);
|
||||
|
||||
// Add to return object
|
||||
ret->Set(NanNew<String>("K1"), K1MatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion1"), d1MatrixWrap);
|
||||
ret->Set(NanNew<String>("K2"), K2MatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion2"), d2MatrixWrap);
|
||||
ret->Set(NanNew<String>("R"), RMatrixWrap);
|
||||
ret->Set(NanNew<String>("t"), tMatrixWrap);
|
||||
ret->Set(NanNew<String>("E"), EMatrixWrap);
|
||||
ret->Set(NanNew<String>("F"), FMatrixWrap);
|
||||
|
||||
// Return
|
||||
NanReturnValue(ret);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
k2 = matFromMatrix(args[6]);
|
||||
d2 = matFromMatrix(args[7]);
|
||||
}
|
||||
|
||||
// Last argument is flags, skipping for now
|
||||
|
||||
// Output mats
|
||||
cv::Mat R, t, E, F;
|
||||
|
||||
// Do the stereo calibration
|
||||
cv::stereoCalibrate(objectPoints, imagePoints1, imagePoints2, k1, d1, k2,
|
||||
d2, imageSize, R, t, E, F);
|
||||
|
||||
// make the return value
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
// Make the output arguments
|
||||
|
||||
// k1
|
||||
Local<Object> K1MatrixWrap = matrixFromMat(k1);
|
||||
|
||||
// d1
|
||||
Local<Object> d1MatrixWrap = matrixFromMat(d1);
|
||||
|
||||
// k2
|
||||
Local<Object> K2MatrixWrap = matrixFromMat(k2);
|
||||
|
||||
// d2
|
||||
Local<Object> d2MatrixWrap = matrixFromMat(d2);
|
||||
|
||||
// R
|
||||
Local<Object> RMatrixWrap = matrixFromMat(R);
|
||||
|
||||
// t
|
||||
Local<Object> tMatrixWrap = matrixFromMat(t);
|
||||
|
||||
// E
|
||||
Local<Object> EMatrixWrap = matrixFromMat(E);
|
||||
|
||||
// F
|
||||
Local<Object> FMatrixWrap = matrixFromMat(F);
|
||||
|
||||
// Add to return object
|
||||
ret->Set(NanNew<String>("K1"), K1MatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion1"), d1MatrixWrap);
|
||||
ret->Set(NanNew<String>("K2"), K2MatrixWrap);
|
||||
ret->Set(NanNew<String>("distortion2"), d2MatrixWrap);
|
||||
ret->Set(NanNew<String>("R"), RMatrixWrap);
|
||||
ret->Set(NanNew<String>("t"), tMatrixWrap);
|
||||
ret->Set(NanNew<String>("E"), EMatrixWrap);
|
||||
ret->Set(NanNew<String>("F"), FMatrixWrap);
|
||||
|
||||
// Return
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::stereoRectify
|
||||
NAN_METHOD(Calib3D::StereoRectify)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::StereoRectify) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg0, the first camera matrix
|
||||
cv::Mat K1 = matFromMatrix(args[0]);
|
||||
// Arg0, the first camera matrix
|
||||
cv::Mat K1 = matFromMatrix(args[0]);
|
||||
|
||||
// Arg1, the first distortion coefficients
|
||||
cv::Mat d1 = matFromMatrix(args[1]);
|
||||
// Arg1, the first distortion coefficients
|
||||
cv::Mat d1 = matFromMatrix(args[1]);
|
||||
|
||||
// Arg2, the second camera matrix
|
||||
cv::Mat K2 = matFromMatrix(args[2]);
|
||||
// Arg2, the second camera matrix
|
||||
cv::Mat K2 = matFromMatrix(args[2]);
|
||||
|
||||
// Arg3, the second distortion coefficients
|
||||
cv::Mat d2 = matFromMatrix(args[3]);
|
||||
// Arg3, the second distortion coefficients
|
||||
cv::Mat d2 = matFromMatrix(args[3]);
|
||||
|
||||
// Arg4, the image size
|
||||
cv::Size imageSize = sizeFromArray(args[4]);
|
||||
// Arg4, the image size
|
||||
cv::Size imageSize = sizeFromArray(args[4]);
|
||||
|
||||
// arg5, the intercamera rotation matrix
|
||||
cv::Mat R = matFromMatrix(args[5]);
|
||||
// arg5, the intercamera rotation matrix
|
||||
cv::Mat R = matFromMatrix(args[5]);
|
||||
|
||||
// Arg6, the intercamera translation vector
|
||||
cv::Mat t = matFromMatrix(args[6]);
|
||||
// Arg6, the intercamera translation vector
|
||||
cv::Mat t = matFromMatrix(args[6]);
|
||||
|
||||
// Arg8, flags, skipping for now
|
||||
// Arg8, flags, skipping for now
|
||||
|
||||
// Arg9, freescaling paremeter, skipping for now
|
||||
// Arg9, freescaling paremeter, skipping for now
|
||||
|
||||
// Arg10, new image size, skipping for now to fix at original image size
|
||||
// Arg10, new image size, skipping for now to fix at original image size
|
||||
|
||||
// Make output matrics
|
||||
cv::Mat R1, R2, P1, P2, Q;
|
||||
// Make output matrics
|
||||
cv::Mat R1, R2, P1, P2, Q;
|
||||
|
||||
// Do the stereo rectification
|
||||
cv::stereoRectify(K1, d1, K2, d2, imageSize, R, t, R1, R2, P1, P2, Q);
|
||||
// Do the stereo rectification
|
||||
cv::stereoRectify(K1, d1, K2, d2, imageSize, R, t, R1, R2, P1, P2, Q);
|
||||
|
||||
// Make the return object
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
// Make the return object
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
|
||||
ret->Set(NanNew<String>("R1"), matrixFromMat(R1));
|
||||
ret->Set(NanNew<String>("R2"), matrixFromMat(R2));
|
||||
ret->Set(NanNew<String>("P1"), matrixFromMat(P1));
|
||||
ret->Set(NanNew<String>("P2"), matrixFromMat(P2));
|
||||
ret->Set(NanNew<String>("Q"), matrixFromMat(Q));
|
||||
ret->Set(NanNew<String>("R1"), matrixFromMat(R1));
|
||||
ret->Set(NanNew<String>("R2"), matrixFromMat(R2));
|
||||
ret->Set(NanNew<String>("P1"), matrixFromMat(P1));
|
||||
ret->Set(NanNew<String>("P2"), matrixFromMat(P2));
|
||||
ret->Set(NanNew<String>("Q"), matrixFromMat(Q));
|
||||
|
||||
// Return the recification parameters
|
||||
NanReturnValue(ret);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
// Return the rectification parameters
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::computeCorrespondEpilines
|
||||
NAN_METHOD(Calib3D::ComputeCorrespondEpilines)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::ComputeCorrespondEpilines) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg0, the image points
|
||||
std::vector<cv::Point2f> points = points2fFromArray(args[0]);
|
||||
// Arg0, the image points
|
||||
std::vector<cv::Point2f> points = points2fFromArray(args[0]);
|
||||
|
||||
// Arg1, the image index (1 or 2)
|
||||
int whichImage = int(args[1]->ToNumber()->Value());
|
||||
// Arg1, the image index (1 or 2)
|
||||
int whichImage = int(args[1]->ToNumber()->Value());
|
||||
|
||||
// Arg2, the fundamental matrix
|
||||
cv::Mat F = matFromMatrix(args[2]);
|
||||
// Arg2, the fundamental matrix
|
||||
cv::Mat F = matFromMatrix(args[2]);
|
||||
|
||||
// compute the lines
|
||||
std::vector<cv::Vec3f> lines;
|
||||
cv::computeCorrespondEpilines(points, whichImage, F, lines);
|
||||
// compute the lines
|
||||
std::vector<cv::Vec3f> lines;
|
||||
cv::computeCorrespondEpilines(points, whichImage, F, lines);
|
||||
|
||||
// Convert the lines to an array of objects (ax + by + c = 0)
|
||||
Local<Array> linesArray = NanNew<Array>(lines.size());
|
||||
for(unsigned int i = 0; i < lines.size(); i++)
|
||||
{
|
||||
Local<Object> line_data = NanNew<Object>();
|
||||
line_data->Set(NanNew<String>("a"), NanNew<Number>(lines[i][0]));
|
||||
line_data->Set(NanNew<String>("b"), NanNew<Number>(lines[i][1]));
|
||||
line_data->Set(NanNew<String>("c"), NanNew<Number>(lines[i][2]));
|
||||
// Convert the lines to an array of objects (ax + by + c = 0)
|
||||
Local<Array> linesArray = NanNew<Array>(lines.size());
|
||||
for(unsigned int i = 0; i < lines.size(); i++)
|
||||
{
|
||||
Local<Object> line_data = NanNew<Object>();
|
||||
line_data->Set(NanNew<String>("a"), NanNew<Number>(lines[i][0]));
|
||||
line_data->Set(NanNew<String>("b"), NanNew<Number>(lines[i][1]));
|
||||
line_data->Set(NanNew<String>("c"), NanNew<Number>(lines[i][2]));
|
||||
|
||||
linesArray->Set(NanNew<Number>(i), line_data);
|
||||
}
|
||||
|
||||
// Return the lines
|
||||
NanReturnValue(linesArray);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
linesArray->Set(NanNew<Number>(i), line_data);
|
||||
}
|
||||
|
||||
// Return the lines
|
||||
NanReturnValue(linesArray);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::reprojectImageTo3D
|
||||
NAN_METHOD(Calib3D::ReprojectImageTo3D)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(Calib3D::ReprojectImageTo3D) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg0, the disparity image
|
||||
cv::Mat disparity = matFromMatrix(args[0]);
|
||||
// Arg0, the disparity image
|
||||
cv::Mat disparity = matFromMatrix(args[0]);
|
||||
|
||||
// Arg1, the depth-to-disparity transformation Q
|
||||
cv::Mat Q = matFromMatrix(args[1]);
|
||||
// Arg1, the depth-to-disparity transformation Q
|
||||
cv::Mat Q = matFromMatrix(args[1]);
|
||||
|
||||
// Arg 2, handle missing values, skipped for now
|
||||
// Arg 2, handle missing values, skipped for now
|
||||
|
||||
// Arg3, output bit depth, skipped for now
|
||||
// Arg3, output bit depth, skipped for now
|
||||
|
||||
// Compute the depth image
|
||||
cv::Mat depthImage;
|
||||
cv::reprojectImageTo3D(disparity, depthImage, Q);
|
||||
// Compute the depth image
|
||||
cv::Mat depthImage;
|
||||
cv::reprojectImageTo3D(disparity, depthImage, Q);
|
||||
|
||||
// Wrap the depth image
|
||||
Local<Object> depthImageMatrix = matrixFromMat(depthImage);
|
||||
// Wrap the depth image
|
||||
Local<Object> depthImageMatrix = matrixFromMat(depthImage);
|
||||
|
||||
NanReturnValue(depthImageMatrix);
|
||||
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
NanReturnValue(depthImageMatrix);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,29 +3,21 @@
|
||||
|
||||
#include "OpenCV.h"
|
||||
|
||||
// Implementation of calib3d.hpp functions
|
||||
|
||||
/**
|
||||
* Implementation of calib3d.hpp functions
|
||||
*/
|
||||
class Calib3D: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
static NAN_METHOD(FindChessboardCorners);
|
||||
|
||||
static NAN_METHOD(DrawChessboardCorners);
|
||||
|
||||
static NAN_METHOD(CalibrateCamera);
|
||||
|
||||
static NAN_METHOD(SolvePnP);
|
||||
|
||||
static NAN_METHOD(GetOptimalNewCameraMatrix);
|
||||
|
||||
static NAN_METHOD(StereoCalibrate);
|
||||
|
||||
static NAN_METHOD(StereoRectify);
|
||||
|
||||
static NAN_METHOD(ComputeCorrespondEpilines);
|
||||
|
||||
static NAN_METHOD(ReprojectImageTo3D);
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(FindChessboardCorners);
|
||||
static NAN_METHOD(DrawChessboardCorners);
|
||||
static NAN_METHOD(CalibrateCamera);
|
||||
static NAN_METHOD(SolvePnP);
|
||||
static NAN_METHOD(GetOptimalNewCameraMatrix);
|
||||
static NAN_METHOD(StereoCalibrate);
|
||||
static NAN_METHOD(StereoRectify);
|
||||
static NAN_METHOD(ComputeCorrespondEpilines);
|
||||
static NAN_METHOD(ReprojectImageTo3D);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
156
src/CamShift.cc
156
src/CamShift.cc
@ -10,30 +10,27 @@
|
||||
|
||||
Persistent<FunctionTemplate> TrackedObject::constructor;
|
||||
|
||||
void
|
||||
TrackedObject::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void TrackedObject::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(TrackedObject::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("TrackedObject"));
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(TrackedObject::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("TrackedObject"));
|
||||
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
// Prototype
|
||||
// Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "track", Track);
|
||||
|
||||
target->Set(NanNew("TrackedObject"), ctor->GetFunction());
|
||||
};
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "track", Track);
|
||||
|
||||
target->Set(NanNew("TrackedObject"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(TrackedObject::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0){
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
@ -41,136 +38,125 @@ NAN_METHOD(TrackedObject::New) {
|
||||
cv::Rect r;
|
||||
int channel = CHANNEL_HUE;
|
||||
|
||||
if (args[1]->IsArray()){
|
||||
Local<Object> v8rec = args[1]->ToObject();
|
||||
if (args[1]->IsArray()) {
|
||||
Local<Object> v8rec = args[1]->ToObject();
|
||||
r = cv::Rect(
|
||||
v8rec->Get(0)->IntegerValue(),
|
||||
v8rec->Get(1)->IntegerValue(),
|
||||
v8rec->Get(2)->IntegerValue() - v8rec->Get(0)->IntegerValue(),
|
||||
v8rec->Get(2)->IntegerValue() - v8rec->Get(0)->IntegerValue(),
|
||||
v8rec->Get(3)->IntegerValue() - v8rec->Get(1)->IntegerValue());
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass rectangle to track")
|
||||
JSTHROW_TYPE("Must pass rectangle to track")
|
||||
}
|
||||
|
||||
if (args[2]->IsObject()){
|
||||
|
||||
if (args[2]->IsObject()) {
|
||||
Local<Object> opts = args[2]->ToObject();
|
||||
|
||||
if (opts->Get(NanNew("channel"))->IsString()){
|
||||
if (opts->Get(NanNew("channel"))->IsString()) {
|
||||
v8::String::Utf8Value c(opts->Get(NanNew("channel"))->ToString());
|
||||
std::string cc = std::string(*c);
|
||||
|
||||
if (cc == "hue" || cc == "h"){
|
||||
channel = CHANNEL_HUE;
|
||||
if (cc == "hue" || cc == "h") {
|
||||
channel = CHANNEL_HUE;
|
||||
}
|
||||
|
||||
if (cc == "saturation" || cc == "s"){
|
||||
channel = CHANNEL_SATURATION;
|
||||
if (cc == "saturation" || cc == "s") {
|
||||
channel = CHANNEL_SATURATION;
|
||||
}
|
||||
|
||||
if (cc == "value" || cc == "v"){
|
||||
channel = CHANNEL_VALUE;
|
||||
|
||||
if (cc == "value" || cc == "v") {
|
||||
channel = CHANNEL_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TrackedObject *to = new TrackedObject(m->mat, r, channel);
|
||||
|
||||
|
||||
TrackedObject *to = new TrackedObject(m->mat, r, channel);
|
||||
|
||||
to->Wrap(args.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
|
||||
void update_chann_image(TrackedObject* t, cv::Mat image){
|
||||
void update_chann_image(TrackedObject* t, cv::Mat image) {
|
||||
// Store HSV Hue Image
|
||||
cv::cvtColor(image, t->hsv, CV_BGR2HSV); // convert to HSV space
|
||||
//mask out-of-range values
|
||||
int vmin = 65, vmax = 256, smin = 55;
|
||||
cv::inRange(t->hsv, //source
|
||||
cv::Scalar(0, smin, MIN(vmin, vmax), 0), //lower bound
|
||||
cv::Scalar(180, 256, MAX(vmin, vmax) ,0), //upper bound
|
||||
t->mask); //destination
|
||||
cv::cvtColor(image, t->hsv, CV_BGR2HSV); // convert to HSV space
|
||||
|
||||
//extract the hue channel, split: src, dest channels
|
||||
// Mask out-of-range values
|
||||
int vmin = 65, vmax = 256, smin = 55;
|
||||
cv::inRange(t->hsv, //source
|
||||
cv::Scalar(0, smin, MIN(vmin, vmax), 0), //lower bound
|
||||
cv::Scalar(180, 256, MAX(vmin, vmax), 0), //upper bound
|
||||
t->mask); //destination
|
||||
|
||||
// Extract the hue channel, split: src, dest channels
|
||||
std::vector<cv::Mat> hsvplanes;
|
||||
cv::split(t->hsv, hsvplanes);
|
||||
t->hue = hsvplanes[t->channel];
|
||||
|
||||
|
||||
}
|
||||
|
||||
TrackedObject::TrackedObject(cv::Mat image, cv::Rect rect, int chan){
|
||||
TrackedObject::TrackedObject(cv::Mat image, cv::Rect rect, int chan) {
|
||||
channel = chan;
|
||||
update_chann_image(this, image);
|
||||
prev_rect = rect;
|
||||
|
||||
|
||||
// Calculate Histogram
|
||||
int hbins = 30, sbins = 32;
|
||||
int histSizes[] = {hbins, sbins};
|
||||
//float hranges[] = { 0, 180 };
|
||||
int histSizes[] = { hbins, sbins };
|
||||
// float hranges[] = { 0, 180 };
|
||||
// saturation varies from 0 (black-gray-white) to
|
||||
// 255 (pure spectrum color)
|
||||
float sranges[] = { 0, 256 };
|
||||
const float* ranges[] = { sranges };
|
||||
|
||||
|
||||
cv::Mat hue_roi = hue(rect);
|
||||
cv::Mat mask_roi = mask(rect);
|
||||
|
||||
cv::calcHist(&hue_roi, 1, 0, mask_roi, hist, 1, histSizes, ranges, true, false);
|
||||
|
||||
cv::calcHist(&hue_roi, 1, 0, mask_roi, hist, 1, histSizes, ranges, true,
|
||||
false);
|
||||
}
|
||||
|
||||
NAN_METHOD(TrackedObject::Track) {
|
||||
SETUP_FUNCTION(TrackedObject)
|
||||
|
||||
|
||||
NAN_METHOD(TrackedObject::Track){
|
||||
SETUP_FUNCTION(TrackedObject)
|
||||
|
||||
if (args.Length() != 1){
|
||||
if (args.Length() != 1) {
|
||||
NanThrowTypeError("track takes an image param");
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
|
||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::RotatedRect r;
|
||||
|
||||
if (self->prev_rect.x <0 ||
|
||||
self->prev_rect.y <0 ||
|
||||
self->prev_rect.width <= 1 ||
|
||||
self->prev_rect.height <= 1){
|
||||
|
||||
if ((self->prev_rect.x < 0) || (self->prev_rect.y < 0)
|
||||
|| (self->prev_rect.width <= 1) || (self->prev_rect.height <= 1)) {
|
||||
return NanThrowTypeError("OPENCV ERROR: prev rectangle is illogical");
|
||||
}
|
||||
|
||||
update_chann_image(self, im->mat);
|
||||
|
||||
cv::Rect backup_prev_rect = cv::Rect(
|
||||
self->prev_rect.x,
|
||||
self->prev_rect.y,
|
||||
self->prev_rect.width,
|
||||
self->prev_rect.height);
|
||||
|
||||
cv::Rect backup_prev_rect = cv::Rect(self->prev_rect.x, self->prev_rect.y,
|
||||
self->prev_rect.width, self->prev_rect.height);
|
||||
|
||||
float sranges[] = { 0, 256 };
|
||||
const float* ranges[] = { sranges };
|
||||
int channel = 0;
|
||||
cv::calcBackProject(&self->hue, 1, &channel, self->hist, self->prob, ranges);
|
||||
|
||||
r = cv::CamShift(self->prob, self->prev_rect,
|
||||
cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1));
|
||||
cv::calcBackProject(&self->hue, 1, &channel, self->hist, self->prob, ranges);
|
||||
|
||||
cv::Rect bounds = r.boundingRect();
|
||||
if (bounds.x >=0 && bounds.y >=0 && bounds.width > 1 && bounds.height > 1){
|
||||
r = cv::CamShift(self->prob, self->prev_rect,
|
||||
cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1));
|
||||
|
||||
cv::Rect bounds = r.boundingRect();
|
||||
if (bounds.x >= 0 && bounds.y >= 0 && bounds.width > 1 && bounds.height > 1) {
|
||||
self->prev_rect = bounds;
|
||||
} else {
|
||||
//printf("CRAP> %i %i %i %i ;", self->prev_rect.x, self->prev_rect.y, self->prev_rect.width, self->prev_rect.height);
|
||||
|
||||
// We have encountered a bug in opencv. Somehow the prev_rect has got mangled, so we
|
||||
// must reset it to a good value.
|
||||
// printf("CRAP> %i %i %i %i ;", self->prev_rect.x, self->prev_rect.y,
|
||||
// self->prev_rect.width, self->prev_rect.height);
|
||||
|
||||
// We have encountered a bug in opencv. Somehow the prev_rect has got
|
||||
// mangled, so we must reset it to a good value.
|
||||
self->prev_rect = backup_prev_rect;
|
||||
}
|
||||
|
||||
v8::Local<v8::Array> arr = NanNew<Array>(4);
|
||||
|
||||
|
||||
arr->Set(0, NanNew<Number>(bounds.x));
|
||||
arr->Set(1, NanNew<Number>(bounds.y));
|
||||
arr->Set(2, NanNew<Number>(bounds.x + bounds.width));
|
||||
@ -180,12 +166,10 @@ NAN_METHOD(TrackedObject::Track){
|
||||
cv::Point2f pts[4];
|
||||
r.points(pts);
|
||||
|
||||
for (int i=0; i<8; i+=2){
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
arr->Set(i, NanNew<Number>(pts[i].x));
|
||||
arr->Set(i+1, NanNew<Number>(pts[i].y));
|
||||
}
|
||||
*/
|
||||
|
||||
NanReturnValue(arr);
|
||||
arr->Set(i + 1, NanNew<Number>(pts[i].y));
|
||||
} */
|
||||
|
||||
NanReturnValue(arr);
|
||||
}
|
||||
|
||||
@ -2,22 +2,21 @@
|
||||
|
||||
|
||||
class TrackedObject: public node::ObjectWrap {
|
||||
public:
|
||||
int channel;
|
||||
cv::Mat hsv;
|
||||
cv::Mat hue;
|
||||
cv::Mat mask;
|
||||
cv::Mat prob;
|
||||
public:
|
||||
int channel;
|
||||
cv::Mat hsv;
|
||||
cv::Mat hue;
|
||||
cv::Mat mask;
|
||||
cv::Mat prob;
|
||||
|
||||
cv::Mat hist;
|
||||
cv::Rect prev_rect;
|
||||
cv::Mat hist;
|
||||
cv::Rect prev_rect;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
TrackedObject(cv::Mat image, cv::Rect rect, int channel);
|
||||
|
||||
JSFUNC(Track);
|
||||
TrackedObject(cv::Mat image, cv::Rect rect, int channel);
|
||||
|
||||
JSFUNC(Track);
|
||||
};
|
||||
|
||||
@ -3,89 +3,94 @@
|
||||
#include "Matrix.h"
|
||||
#include <nan.h>
|
||||
|
||||
|
||||
Persistent<FunctionTemplate> CascadeClassifierWrap::constructor;
|
||||
|
||||
void
|
||||
CascadeClassifierWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void CascadeClassifierWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(CascadeClassifierWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("CascadeClassifier"));
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate> (CascadeClassifierWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("CascadeClassifier"));
|
||||
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
// Prototype
|
||||
// Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "detectMultiScale", DetectMultiScale);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "detectMultiScale", DetectMultiScale);
|
||||
|
||||
target->Set(NanNew("CascadeClassifier"), ctor->GetFunction());
|
||||
};
|
||||
target->Set(NanNew("CascadeClassifier"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(CascadeClassifierWrap::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
CascadeClassifierWrap *pt = new CascadeClassifierWrap(*args[0]);
|
||||
pt->Wrap(args.This());
|
||||
NanReturnValue( args.This() );
|
||||
}
|
||||
|
||||
CascadeClassifierWrap::CascadeClassifierWrap(v8::Value* fileName) {
|
||||
std::string filename;
|
||||
filename = std::string(*NanAsciiString(fileName->ToString()));
|
||||
|
||||
CascadeClassifierWrap::CascadeClassifierWrap(v8::Value* fileName){
|
||||
std::string filename;
|
||||
filename = std::string(*NanAsciiString(fileName->ToString()));
|
||||
|
||||
|
||||
if (!cc.load(filename.c_str())){
|
||||
if (!cc.load(filename.c_str())) {
|
||||
NanThrowTypeError("Error loading file");
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncDetectMultiScale: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncDetectMultiScale(NanCallback *callback, CascadeClassifierWrap *cc,
|
||||
Matrix* im, double scale, int neighbors, int minw, int minh) :
|
||||
NanAsyncWorker(callback),
|
||||
cc(cc),
|
||||
im(im),
|
||||
scale(scale),
|
||||
neighbors(neighbors),
|
||||
minw(minw),
|
||||
minh(minh) {
|
||||
}
|
||||
|
||||
~AsyncDetectMultiScale() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AsyncDetectMultiScale : public NanAsyncWorker {
|
||||
public:
|
||||
AsyncDetectMultiScale(NanCallback *callback, CascadeClassifierWrap *cc, Matrix* im, double scale, int neighbors, int minw, int minh) : NanAsyncWorker(callback), cc(cc), im(im), scale(scale), neighbors(neighbors), minw(minw), minh(minh) {}
|
||||
~AsyncDetectMultiScale() {}
|
||||
|
||||
void Execute () {
|
||||
void Execute() {
|
||||
try {
|
||||
std::vector<cv::Rect> objects;
|
||||
std::vector < cv::Rect > objects;
|
||||
|
||||
cv::Mat gray;
|
||||
|
||||
if(this->im->mat.channels() != 1) {
|
||||
if (this->im->mat.channels() != 1) {
|
||||
cvtColor(this->im->mat, gray, CV_BGR2GRAY);
|
||||
equalizeHist( gray, gray);
|
||||
equalizeHist(gray, gray);
|
||||
} else {
|
||||
gray = this->im->mat;
|
||||
}
|
||||
this->cc->cc.detectMultiScale(gray, objects, this->scale, this->neighbors, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(this->minw, this->minh));
|
||||
this->cc->cc.detectMultiScale(gray, objects, this->scale, this->neighbors,
|
||||
0 | CV_HAAR_SCALE_IMAGE, cv::Size(this->minw, this->minh));
|
||||
res = objects;
|
||||
}
|
||||
catch( cv::Exception& e ){
|
||||
} catch (cv::Exception& e) {
|
||||
SetErrorMessage(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void HandleOKCallback () {
|
||||
void HandleOKCallback() {
|
||||
NanScope();
|
||||
// this->matrix->Unref();
|
||||
|
||||
Handle<Value> argv[2];
|
||||
v8::Local<v8::Array> arr = NanNew<v8::Array>(this->res.size());
|
||||
Handle < Value > argv[2];
|
||||
v8::Local < v8::Array > arr = NanNew < v8::Array > (this->res.size());
|
||||
|
||||
for(unsigned int i = 0; i < this->res.size(); i++ ){
|
||||
v8::Local<v8::Object> x = NanNew<v8::Object>();
|
||||
x->Set(NanNew("x"), NanNew<Number>(this->res[i].x));
|
||||
x->Set(NanNew("y"), NanNew<Number>(this->res[i].y));
|
||||
x->Set(NanNew("width"), NanNew<Number>(this->res[i].width));
|
||||
x->Set(NanNew("height"), NanNew<Number>(this->res[i].height));
|
||||
for (unsigned int i = 0; i < this->res.size(); i++) {
|
||||
v8::Local < v8::Object > x = NanNew<v8::Object>();
|
||||
x->Set(NanNew("x"), NanNew < Number > (this->res[i].x));
|
||||
x->Set(NanNew("y"), NanNew < Number > (this->res[i].y));
|
||||
x->Set(NanNew("width"), NanNew < Number > (this->res[i].width));
|
||||
x->Set(NanNew("height"), NanNew < Number > (this->res[i].height));
|
||||
arr->Set(i, x);
|
||||
}
|
||||
|
||||
@ -97,54 +102,50 @@ class AsyncDetectMultiScale : public NanAsyncWorker {
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
CascadeClassifierWrap *cc;
|
||||
Matrix* im;
|
||||
double scale;
|
||||
int neighbors;
|
||||
int minw;
|
||||
int minh;
|
||||
std::vector<cv::Rect> res;
|
||||
|
||||
private:
|
||||
CascadeClassifierWrap *cc;
|
||||
Matrix* im;
|
||||
double scale;
|
||||
int neighbors;
|
||||
int minw;
|
||||
int minh;
|
||||
std::vector<cv::Rect> res;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
NAN_METHOD(CascadeClassifierWrap::DetectMultiScale){
|
||||
NAN_METHOD(CascadeClassifierWrap::DetectMultiScale) {
|
||||
NanScope();
|
||||
|
||||
CascadeClassifierWrap *self = ObjectWrap::Unwrap<CascadeClassifierWrap>(args.This());
|
||||
CascadeClassifierWrap *self = ObjectWrap::Unwrap<CascadeClassifierWrap> (args.This());
|
||||
|
||||
if (args.Length() < 2){
|
||||
if (args.Length() < 2) {
|
||||
NanThrowTypeError("detectMultiScale takes at least 2 args");
|
||||
}
|
||||
|
||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
Matrix *im = ObjectWrap::Unwrap < Matrix > (args[0]->ToObject());
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
double scale = 1.1;
|
||||
if (args.Length() > 2 && args[2]->IsNumber())
|
||||
if (args.Length() > 2 && args[2]->IsNumber()) {
|
||||
scale = args[2]->NumberValue();
|
||||
}
|
||||
|
||||
int neighbors = 2;
|
||||
if (args.Length() > 3 && args[3]->IsInt32())
|
||||
if (args.Length() > 3 && args[3]->IsInt32()) {
|
||||
neighbors = args[3]->IntegerValue();
|
||||
}
|
||||
|
||||
int minw = 30;
|
||||
int minh = 30;
|
||||
if (args.Length() > 5 && args[4]->IsInt32() && args[5]->IsInt32()){
|
||||
if (args.Length() > 5 && args[4]->IsInt32() && args[5]->IsInt32()) {
|
||||
minw = args[4]->IntegerValue();
|
||||
minh = args[5]->IntegerValue();
|
||||
}
|
||||
|
||||
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
|
||||
NanAsyncQueueWorker( new AsyncDetectMultiScale(callback, self, im, scale, neighbors, minw, minh) );
|
||||
NanAsyncQueueWorker( new AsyncDetectMultiScale(callback, self, im, scale,
|
||||
neighbors, minw, minh));
|
||||
NanReturnUndefined();
|
||||
|
||||
}
|
||||
|
||||
@ -1,20 +1,19 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class CascadeClassifierWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::CascadeClassifier cc;
|
||||
public:
|
||||
cv::CascadeClassifier cc;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
CascadeClassifierWrap(v8::Value* fileName);
|
||||
CascadeClassifierWrap(v8::Value* fileName);
|
||||
|
||||
//static Handle<Value> LoadHaarClassifierCascade(const v8::Arguments&);
|
||||
|
||||
static NAN_METHOD(DetectMultiScale);
|
||||
|
||||
static void EIO_DetectMultiScale(uv_work_t *req);
|
||||
static int EIO_AfterDetectMultiScale(uv_work_t *req);
|
||||
|
||||
static void EIO_DetectMultiScale(uv_work_t *req);
|
||||
static int EIO_AfterDetectMultiScale(uv_work_t *req);
|
||||
};
|
||||
|
||||
@ -5,10 +5,9 @@
|
||||
obj->Set(NanNew<String>(#C), NanNew<Integer>(C));
|
||||
|
||||
#define CONST_ENUM(C) \
|
||||
obj->Set(NanNew<String>(#C), NanNew<Integer>((int)(cv::C)));
|
||||
obj->Set(NanNew<String>(#C), NanNew<Integer>((int)(cv::C)));
|
||||
|
||||
void
|
||||
Constants::Init(Handle<Object> target) {
|
||||
void Constants::Init(Handle<Object> target) {
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Constants: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
};
|
||||
|
||||
319
src/Contours.cc
319
src/Contours.cc
@ -6,81 +6,77 @@
|
||||
|
||||
v8::Persistent<FunctionTemplate> Contour::constructor;
|
||||
|
||||
void Contour::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
void
|
||||
Contour::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
//Class/contructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Contour::New);
|
||||
// Class/contructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Contour::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("Contours"));
|
||||
|
||||
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "point", Point);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "size", Size);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "cornerCount", CornerCount);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "area", Area);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "arcLength", ArcLength);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "approxPolyDP", ApproxPolyDP);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "convexHull", ConvexHull);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "boundingRect", BoundingRect);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "minAreaRect", MinAreaRect);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "fitEllipse", FitEllipse);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "isConvex", IsConvex);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "moments", Moments);
|
||||
// Prototype
|
||||
// Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "point", Point);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "size", Size);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "cornerCount", CornerCount);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "area", Area);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "arcLength", ArcLength);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "approxPolyDP", ApproxPolyDP);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "convexHull", ConvexHull);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "boundingRect", BoundingRect);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "minAreaRect", MinAreaRect);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "fitEllipse", FitEllipse);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "isConvex", IsConvex);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "moments", Moments);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "hierarchy", Hierarchy);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "serialize", Serialize);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "deserialize", Deserialize);
|
||||
target->Set(NanNew("Contours"), ctor->GetFunction());
|
||||
target->Set(NanNew("Contours"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
|
||||
NAN_METHOD(Contour::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
Contour *contours;
|
||||
contours = new Contour;
|
||||
Contour *contours;
|
||||
contours = new Contour;
|
||||
|
||||
contours->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
contours->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
|
||||
Contour::Contour(): ObjectWrap() {
|
||||
Contour::Contour() :
|
||||
ObjectWrap() {
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Point) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
int index = args[1]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
int index = args[1]->NumberValue();
|
||||
|
||||
cv::Point point = self->contours[pos][index];
|
||||
cv::Point point = self->contours[pos][index];
|
||||
|
||||
Local<Object> data = NanNew<Object>();
|
||||
data->Set(NanNew("x"), NanNew<Number>(point.x));
|
||||
data->Set(NanNew("y"), NanNew<Number>(point.y));
|
||||
Local<Object> data = NanNew<Object>();
|
||||
data->Set(NanNew("x"), NanNew<Number>(point.x));
|
||||
data->Set(NanNew("y"), NanNew<Number>(point.y));
|
||||
|
||||
NanReturnValue(data);
|
||||
NanReturnValue(data);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Points) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
vector<cv::Point> points = self->contours[pos];
|
||||
|
||||
Local<Array> data = NanNew<Array>(points.size());
|
||||
Local<Array> data = NanNew<Array>(points.size());
|
||||
|
||||
for (std::vector<int>::size_type i = 0; i != points.size(); i++) {
|
||||
Local<Object> point_data = NanNew<Object>();
|
||||
@ -93,204 +89,194 @@ NAN_METHOD(Contour::Points) {
|
||||
NanReturnValue(data);
|
||||
}
|
||||
|
||||
// FIXME: this sould better be called "Length" as ``Contours`` is an Array like structure
|
||||
// also, this would allow to use ``Size`` for the function returning the number of corners
|
||||
// in the contour for better consistency with OpenCV.
|
||||
// FIXME: this should better be called "Length" as ``Contours`` is an Array like
|
||||
// structure also, this would allow to use ``Size`` for the function returning
|
||||
// the number of corners in the contour for better consistency with OpenCV.
|
||||
NAN_METHOD(Contour::Size) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
NanReturnValue(NanNew<Number>(self->contours.size()));
|
||||
NanReturnValue(NanNew<Number>(self->contours.size()));
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::CornerCount) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
NanReturnValue(NanNew<Number>(self->contours[pos].size()));
|
||||
NanReturnValue(NanNew<Number>(self->contours[pos].size()));
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::Area) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
//NanReturnValue(NanNew<Number>(contourArea(self->contours)));
|
||||
NanReturnValue(NanNew<Number>(contourArea(cv::Mat(self->contours[pos]))));
|
||||
// NanReturnValue(NanNew<Number>(contourArea(self->contours)));
|
||||
NanReturnValue(NanNew<Number>(contourArea(cv::Mat(self->contours[pos]))));
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::ArcLength) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
bool isClosed = args[1]->BooleanValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
bool isClosed = args[1]->BooleanValue();
|
||||
|
||||
NanReturnValue(NanNew<Number>(arcLength(cv::Mat(self->contours[pos]), isClosed)));
|
||||
NanReturnValue(NanNew<Number>(arcLength(cv::Mat(self->contours[pos]), isClosed)));
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::ApproxPolyDP) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
double epsilon = args[1]->NumberValue();
|
||||
bool isClosed = args[2]->BooleanValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
double epsilon = args[1]->NumberValue();
|
||||
bool isClosed = args[2]->BooleanValue();
|
||||
|
||||
cv::Mat approxed;
|
||||
approxPolyDP(cv::Mat(self->contours[pos]), approxed, epsilon, isClosed);
|
||||
approxed.copyTo(self->contours[pos]);
|
||||
cv::Mat approxed;
|
||||
approxPolyDP(cv::Mat(self->contours[pos]), approxed, epsilon, isClosed);
|
||||
approxed.copyTo(self->contours[pos]);
|
||||
|
||||
NanReturnNull();
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::ConvexHull) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
int pos = args[0]->NumberValue();
|
||||
bool clockwise = args[1]->BooleanValue();
|
||||
int pos = args[0]->NumberValue();
|
||||
bool clockwise = args[1]->BooleanValue();
|
||||
|
||||
cv::Mat hull;
|
||||
cv::convexHull(cv::Mat(self->contours[pos]), hull, clockwise);
|
||||
hull.copyTo(self->contours[pos]);
|
||||
cv::Mat hull;
|
||||
cv::convexHull(cv::Mat(self->contours[pos]), hull, clockwise);
|
||||
hull.copyTo(self->contours[pos]);
|
||||
|
||||
NanReturnNull();
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::BoundingRect) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
cv::Rect bounding = cv::boundingRect(cv::Mat(self->contours[pos]));
|
||||
Local<Object> rect = NanNew<Object>();
|
||||
cv::Rect bounding = cv::boundingRect(cv::Mat(self->contours[pos]));
|
||||
Local<Object> rect = NanNew<Object>();
|
||||
|
||||
rect->Set(NanNew("x"), NanNew<Number>(bounding.x));
|
||||
rect->Set(NanNew("y"), NanNew<Number>(bounding.y));
|
||||
rect->Set(NanNew("width"), NanNew<Number>(bounding.width));
|
||||
rect->Set(NanNew("height"), NanNew<Number>(bounding.height));
|
||||
rect->Set(NanNew("x"), NanNew<Number>(bounding.x));
|
||||
rect->Set(NanNew("y"), NanNew<Number>(bounding.y));
|
||||
rect->Set(NanNew("width"), NanNew<Number>(bounding.width));
|
||||
rect->Set(NanNew("height"), NanNew<Number>(bounding.height));
|
||||
|
||||
NanReturnValue(rect);
|
||||
NanReturnValue(rect);
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::MinAreaRect) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
cv::RotatedRect minimum = cv::minAreaRect(cv::Mat(self->contours[pos]));
|
||||
cv::RotatedRect minimum = cv::minAreaRect(cv::Mat(self->contours[pos]));
|
||||
|
||||
Local<Object> rect = NanNew<Object>();
|
||||
rect->Set(NanNew("angle"), NanNew<Number>(minimum.angle));
|
||||
Local<Object> rect = NanNew<Object>();
|
||||
rect->Set(NanNew("angle"), NanNew<Number>(minimum.angle));
|
||||
|
||||
Local<Object> size = NanNew<Object>();
|
||||
size->Set(NanNew("height"), NanNew<Number>(minimum.size.height));
|
||||
size->Set(NanNew("width"), NanNew<Number>(minimum.size.width));
|
||||
rect->Set(NanNew("size"), size);
|
||||
Local<Object> size = NanNew<Object>();
|
||||
size->Set(NanNew("height"), NanNew<Number>(minimum.size.height));
|
||||
size->Set(NanNew("width"), NanNew<Number>(minimum.size.width));
|
||||
rect->Set(NanNew("size"), size);
|
||||
|
||||
Local<Object> center = NanNew<Object>();
|
||||
center->Set(NanNew("x"), NanNew<Number>(minimum.center.x));
|
||||
center->Set(NanNew("y"), NanNew<Number>(minimum.center.y));
|
||||
Local<Object> center = NanNew<Object>();
|
||||
center->Set(NanNew("x"), NanNew<Number>(minimum.center.x));
|
||||
center->Set(NanNew("y"), NanNew<Number>(minimum.center.y));
|
||||
|
||||
v8::Local<v8::Array> points = NanNew<Array>(4);
|
||||
v8::Local<v8::Array> points = NanNew<Array>(4);
|
||||
|
||||
cv::Point2f rect_points[4];
|
||||
minimum.points(rect_points);
|
||||
cv::Point2f rect_points[4];
|
||||
minimum.points(rect_points);
|
||||
|
||||
for (unsigned int i=0; i<4; i++){
|
||||
Local<Object> point = NanNew<Object>();
|
||||
point->Set(NanNew("x"), NanNew<Number>(rect_points[i].x));
|
||||
point->Set(NanNew("y"), NanNew<Number>(rect_points[i].y));
|
||||
points->Set(i, point);
|
||||
}
|
||||
for (unsigned int i=0; i<4; i++) {
|
||||
Local<Object> point = NanNew<Object>();
|
||||
point->Set(NanNew("x"), NanNew<Number>(rect_points[i].x));
|
||||
point->Set(NanNew("y"), NanNew<Number>(rect_points[i].y));
|
||||
points->Set(i, point);
|
||||
}
|
||||
|
||||
rect->Set(NanNew("points"), points);
|
||||
rect->Set(NanNew("points"), points);
|
||||
|
||||
NanReturnValue(rect);
|
||||
NanReturnValue(rect);
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(Contour::FitEllipse) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
if(self->contours[pos].size() >= 5){ //Minimum number for an ellipse
|
||||
cv::RotatedRect ellipse = cv::fitEllipse(cv::Mat(self->contours[pos]));
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
Local<Object> jsEllipse = NanNew<Object>();
|
||||
jsEllipse->Set(NanNew("angle"), NanNew<Number>(ellipse.angle));
|
||||
if (self->contours[pos].size() >= 5) { // Minimum number for an ellipse
|
||||
cv::RotatedRect ellipse = cv::fitEllipse(cv::Mat(self->contours[pos]));
|
||||
|
||||
Local<Object> size = NanNew<Object>();
|
||||
size->Set(NanNew("height"), NanNew<Number>(ellipse.size.height));
|
||||
size->Set(NanNew("width"), NanNew<Number>(ellipse.size.width));
|
||||
jsEllipse->Set(NanNew("size"), size);
|
||||
Local<Object> jsEllipse = NanNew<Object>();
|
||||
jsEllipse->Set(NanNew("angle"), NanNew<Number>(ellipse.angle));
|
||||
|
||||
Local<Object> center = NanNew<Object>();
|
||||
center->Set(NanNew("x"), NanNew<Number>(ellipse.center.x));
|
||||
center->Set(NanNew("y"), NanNew<Number>(ellipse.center.y));
|
||||
jsEllipse->Set(NanNew("center"), center);
|
||||
Local<Object> size = NanNew<Object>();
|
||||
size->Set(NanNew("height"), NanNew<Number>(ellipse.size.height));
|
||||
size->Set(NanNew("width"), NanNew<Number>(ellipse.size.width));
|
||||
jsEllipse->Set(NanNew("size"), size);
|
||||
|
||||
NanReturnValue(jsEllipse);
|
||||
}
|
||||
Local<Object> center = NanNew<Object>();
|
||||
center->Set(NanNew("x"), NanNew<Number>(ellipse.center.x));
|
||||
center->Set(NanNew("y"), NanNew<Number>(ellipse.center.y));
|
||||
jsEllipse->Set(NanNew("center"), center);
|
||||
|
||||
NanReturnNull();
|
||||
NanReturnValue(jsEllipse);
|
||||
}
|
||||
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
|
||||
|
||||
NAN_METHOD(Contour::IsConvex) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
NanReturnValue(NanNew<Boolean>(isContourConvex(cv::Mat(self->contours[pos]))));
|
||||
NanReturnValue(NanNew<Boolean>(isContourConvex(cv::Mat(self->contours[pos]))));
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Moments) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->NumberValue();
|
||||
|
||||
/// Get the moments
|
||||
cv::Moments mu = moments( self->contours[pos], false );
|
||||
|
||||
Local<Object> res = NanNew<Object>();
|
||||
// Get the moments
|
||||
cv::Moments mu = moments( self->contours[pos], false );
|
||||
|
||||
res->Set(NanNew("m00"), NanNew<Number>(mu.m00));
|
||||
res->Set(NanNew("m10"), NanNew<Number>(mu.m10));
|
||||
res->Set(NanNew("m01"), NanNew<Number>(mu.m01));
|
||||
res->Set(NanNew("m11"), NanNew<Number>(mu.m11));
|
||||
Local<Object> res = NanNew<Object>();
|
||||
|
||||
NanReturnValue(res);
|
||||
res->Set(NanNew("m00"), NanNew<Number>(mu.m00));
|
||||
res->Set(NanNew("m10"), NanNew<Number>(mu.m10));
|
||||
res->Set(NanNew("m01"), NanNew<Number>(mu.m01));
|
||||
res->Set(NanNew("m11"), NanNew<Number>(mu.m11));
|
||||
|
||||
NanReturnValue(res);
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Hierarchy) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
int pos = args[0]->IntegerValue();
|
||||
|
||||
cv::Vec4i hierarchy = self->hierarchy[pos];
|
||||
|
||||
|
||||
Local<Array> res = NanNew<Array>(4);
|
||||
|
||||
res->Set(0, NanNew<Number>(hierarchy[0]));
|
||||
@ -302,12 +288,12 @@ NAN_METHOD(Contour::Hierarchy) {
|
||||
}
|
||||
|
||||
NAN_METHOD(Contour::Serialize) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This());
|
||||
|
||||
Local<Array> contours_data = NanNew<Array>(self->contours.size());
|
||||
|
||||
|
||||
for (std::vector<int>::size_type i = 0; i != self->contours.size(); i++) {
|
||||
vector<cv::Point> points = self->contours[i];
|
||||
Local<Array> contour_data = NanNew<Array>(points.size());
|
||||
@ -319,8 +305,7 @@ NAN_METHOD(Contour::Serialize) {
|
||||
|
||||
contour_data->Set(j, point_data);
|
||||
}
|
||||
|
||||
contours_data->Set(i, contour_data);
|
||||
contours_data->Set(i, contour_data);
|
||||
}
|
||||
|
||||
Local<Array> hierarchy_data = NanNew<Array>(self->hierarchy.size());
|
||||
@ -383,6 +368,6 @@ NAN_METHOD(Contour::Deserialize) {
|
||||
|
||||
self->contours = contours_res;
|
||||
self->hierarchy = hierarchy_res;
|
||||
|
||||
|
||||
NanReturnNull();
|
||||
}
|
||||
|
||||
@ -3,20 +3,19 @@
|
||||
using namespace std;
|
||||
|
||||
class Contour: public node::ObjectWrap {
|
||||
public:
|
||||
|
||||
cv::Mat mat;
|
||||
vector<vector<cv::Point> > contours;
|
||||
public:
|
||||
cv::Mat mat;
|
||||
vector<vector<cv::Point> > contours;
|
||||
vector<cv::Vec4i> hierarchy;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
Contour();
|
||||
Contour();
|
||||
|
||||
JSFUNC(Point)
|
||||
JSFUNC(Points)
|
||||
JSFUNC(Point)
|
||||
JSFUNC(Points)
|
||||
JSFUNC(Size)
|
||||
JSFUNC(CornerCount)
|
||||
JSFUNC(Area)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "FaceRecognizer.h"
|
||||
#include "OpenCV.h"
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
#include "Matrix.h"
|
||||
#include <nan.h>
|
||||
@ -11,12 +11,12 @@
|
||||
#define FISHER 2
|
||||
|
||||
// Todo, move somewhere useful
|
||||
cv::Mat fromMatrixOrFilename(Local<Value> v){
|
||||
cv::Mat fromMatrixOrFilename(Local<Value> v) {
|
||||
cv::Mat im;
|
||||
if (v->IsString()){
|
||||
if (v->IsString()) {
|
||||
std::string filename = std::string(*NanAsciiString(v->ToString()));
|
||||
im = cv::imread(filename);
|
||||
//std::cout<< im.size();
|
||||
// std::cout<< im.size();
|
||||
} else {
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(v->ToObject());
|
||||
im = img->mat;
|
||||
@ -24,42 +24,41 @@ cv::Mat fromMatrixOrFilename(Local<Value> v){
|
||||
return im;
|
||||
}
|
||||
|
||||
|
||||
void AsyncPredict(uv_work_t *req);
|
||||
void AfterAsyncPredict(uv_work_t *req);
|
||||
|
||||
Persistent<FunctionTemplate> FaceRecognizerWrap::constructor;
|
||||
|
||||
void
|
||||
FaceRecognizerWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void FaceRecognizerWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(FaceRecognizerWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("FaceRecognizer"));
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(FaceRecognizerWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("FaceRecognizer"));
|
||||
|
||||
NODE_SET_METHOD(ctor, "createLBPHFaceRecognizer", CreateLBPH);
|
||||
NODE_SET_METHOD(ctor, "createEigenFaceRecognizer", CreateEigen);
|
||||
NODE_SET_METHOD(ctor, "createFisherFaceRecognizer", CreateFisher);
|
||||
NODE_SET_METHOD(ctor, "createLBPHFaceRecognizer", CreateLBPH);
|
||||
NODE_SET_METHOD(ctor, "createEigenFaceRecognizer", CreateEigen);
|
||||
NODE_SET_METHOD(ctor, "createFisherFaceRecognizer", CreateFisher);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "trainSync", TrainSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "updateSync", UpdateSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "predictSync", PredictSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "saveSync", SaveSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "loadSync", LoadSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "trainSync", TrainSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "updateSync", UpdateSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "predictSync", PredictSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "saveSync", SaveSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "loadSync", LoadSync);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "getMat", GetMat);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "getMat", GetMat);
|
||||
|
||||
target->Set(NanNew("FaceRecognizer"), ctor->GetFunction());
|
||||
target->Set(NanNew("FaceRecognizer"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
// By default initialize LBPH
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(1, 8, 8, 8, 80.0);
|
||||
@ -85,13 +84,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateLBPH) {
|
||||
DOUBLE_FROM_ARGS(threshold, 4)
|
||||
|
||||
Local<Object> n = NanNew(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(
|
||||
radius, neighbors, grid_x, grid_y, threshold
|
||||
);
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(radius,
|
||||
neighbors, grid_x, grid_y, threshold);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);
|
||||
|
||||
pt->Wrap(n);
|
||||
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
@ -105,13 +102,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateEigen) {
|
||||
DOUBLE_FROM_ARGS(threshold, 1)
|
||||
|
||||
Local<Object> n = NanNew(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createEigenFaceRecognizer(
|
||||
components, threshold
|
||||
);
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createEigenFaceRecognizer(components,
|
||||
threshold);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, EIGEN);
|
||||
|
||||
pt->Wrap(n);
|
||||
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
@ -126,70 +121,64 @@ NAN_METHOD(FaceRecognizerWrap::CreateFisher) {
|
||||
|
||||
Local<Object> n = NanNew(FaceRecognizerWrap::constructor)->GetFunction()->NewInstance();
|
||||
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createFisherFaceRecognizer(
|
||||
components, threshold
|
||||
);
|
||||
cv::Ptr<cv::FaceRecognizer> f = cv::createFisherFaceRecognizer(components,
|
||||
threshold);
|
||||
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, FISHER);
|
||||
|
||||
pt->Wrap(n);
|
||||
|
||||
NanReturnValue( n );
|
||||
}
|
||||
|
||||
|
||||
FaceRecognizerWrap::FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f, int type){
|
||||
FaceRecognizerWrap::FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f,
|
||||
int type) {
|
||||
rec = f;
|
||||
typ = type;
|
||||
}
|
||||
|
||||
Handle<Value> UnwrapTrainingData(_NAN_METHOD_ARGS_TYPE args,
|
||||
cv::vector<cv::Mat>* images, cv::vector<int>* labels) {
|
||||
|
||||
|
||||
|
||||
Handle<Value> UnwrapTrainingData(_NAN_METHOD_ARGS_TYPE args, cv::vector<cv::Mat>* images, cv::vector<int>* labels){
|
||||
|
||||
|
||||
if (args.Length() < 1 || !args[0]->IsArray()){
|
||||
if (args.Length() < 1 || !args[0]->IsArray()) {
|
||||
JSTHROW("FaceRecognizer.train takes a list of [<int> label, image] tuples")
|
||||
}
|
||||
|
||||
|
||||
// Iterate through [[label, image], ...] etc, and add matrix / label to vectors
|
||||
//const
|
||||
//Local<Array> tuples = v8::Array::Cast(*args[0]);
|
||||
// const Local<Array> tuples = v8::Array::Cast(*args[0]);
|
||||
const Local<Array> tuples = Local<Array>::Cast(args[0]);
|
||||
|
||||
|
||||
const uint32_t length = tuples->Length();
|
||||
for (uint32_t i=0 ; i<length ; ++i){
|
||||
const Local<Value> val = tuples->Get(i);
|
||||
for (uint32_t i=0; i<length; ++i) {
|
||||
const Local<Value> val = tuples->Get(i);
|
||||
|
||||
if (!val->IsArray()){
|
||||
JSTHROW("train takes a list of [label, image] tuples")
|
||||
}
|
||||
if (!val->IsArray()) {
|
||||
JSTHROW("train takes a list of [label, image] tuples")
|
||||
}
|
||||
|
||||
Local<Array> valarr = Local<Array>::Cast(val);
|
||||
Local<Array> valarr = Local<Array>::Cast(val);
|
||||
|
||||
if (valarr->Length() != 2 || !valarr->Get(0)->IsInt32()){
|
||||
JSTHROW("train takes a list of [label, image] tuples")
|
||||
}
|
||||
if (valarr->Length() != 2 || !valarr->Get(0)->IsInt32()) {
|
||||
JSTHROW("train takes a list of [label, image] tuples")
|
||||
}
|
||||
|
||||
int label = valarr->Get(0)->Uint32Value();
|
||||
cv::Mat im = fromMatrixOrFilename(valarr->Get(1));
|
||||
im = im.clone();
|
||||
cv::cvtColor(im, im, CV_RGB2GRAY);
|
||||
labels->push_back(label);
|
||||
images->push_back(im);
|
||||
int label = valarr->Get(0)->Uint32Value();
|
||||
cv::Mat im = fromMatrixOrFilename(valarr->Get(1));
|
||||
im = im.clone();
|
||||
cv::cvtColor(im, im, CV_RGB2GRAY);
|
||||
labels->push_back(label);
|
||||
images->push_back(im);
|
||||
}
|
||||
return NanUndefined();
|
||||
return NanUndefined();
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::TrainSync){
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
NAN_METHOD(FaceRecognizerWrap::TrainSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
|
||||
cv::vector<cv::Mat> images;
|
||||
cv::vector<int> labels;
|
||||
|
||||
Handle<Value> exception = UnwrapTrainingData(args, &images, &labels);
|
||||
if (!exception->IsUndefined()){
|
||||
NanReturnValue(exception);//FIXME: not too sure about returning exceptions like this
|
||||
if (!exception->IsUndefined()) {
|
||||
NanReturnValue(exception); // FIXME: not too sure about returning exceptions like this
|
||||
}
|
||||
|
||||
self->rec->train(images, labels);
|
||||
@ -197,24 +186,22 @@ NAN_METHOD(FaceRecognizerWrap::TrainSync){
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::UpdateSync){
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
NAN_METHOD(FaceRecognizerWrap::UpdateSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
|
||||
|
||||
if (self->typ == EIGEN){
|
||||
if (self->typ == EIGEN) {
|
||||
JSTHROW("Eigen Recognizer does not support update")
|
||||
}
|
||||
if (self->typ == FISHER){
|
||||
if (self->typ == FISHER) {
|
||||
JSTHROW("Fisher Recognizer does not support update")
|
||||
}
|
||||
|
||||
cv::vector<cv::Mat> images;
|
||||
cv::vector<int> labels;
|
||||
|
||||
|
||||
Handle<Value> exception = UnwrapTrainingData(args, &images, &labels);
|
||||
if (!exception->IsUndefined()){
|
||||
JSTHROW( exception );
|
||||
if (!exception->IsUndefined()) {
|
||||
JSTHROW(exception);
|
||||
}
|
||||
|
||||
self->rec->update(images, labels);
|
||||
@ -222,13 +209,12 @@ NAN_METHOD(FaceRecognizerWrap::UpdateSync){
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::PredictSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::PredictSync){
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
|
||||
cv::Mat im = fromMatrixOrFilename(args[0]);//TODO CHECK!
|
||||
cv::Mat im = fromMatrixOrFilename(args[0]); // TODO CHECK!
|
||||
cv::cvtColor(im, im, CV_RGB2GRAY);
|
||||
// int predictedLabel = self->rec->predict(im);
|
||||
// int predictedLabel = self->rec->predict(im);
|
||||
|
||||
int predictedLabel = -1;
|
||||
double confidence = 0.0;
|
||||
@ -241,10 +227,9 @@ NAN_METHOD(FaceRecognizerWrap::PredictSync){
|
||||
NanReturnValue(res);
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::SaveSync){
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!args[0]->IsString()){
|
||||
NAN_METHOD(FaceRecognizerWrap::SaveSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!args[0]->IsString()) {
|
||||
JSTHROW("Save takes a filename")
|
||||
}
|
||||
std::string filename = std::string(*NanAsciiString(args[0]->ToString()));
|
||||
@ -252,9 +237,9 @@ NAN_METHOD(FaceRecognizerWrap::SaveSync){
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::LoadSync){
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!args[0]->IsString()){
|
||||
NAN_METHOD(FaceRecognizerWrap::LoadSync) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!args[0]->IsString()) {
|
||||
JSTHROW("Load takes a filename")
|
||||
}
|
||||
std::string filename = std::string(*NanAsciiString(args[0]->ToString()));
|
||||
@ -262,9 +247,9 @@ NAN_METHOD(FaceRecognizerWrap::LoadSync){
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(FaceRecognizerWrap::GetMat){
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!args[0]->IsString()){
|
||||
NAN_METHOD(FaceRecognizerWrap::GetMat) {
|
||||
SETUP_FUNCTION(FaceRecognizerWrap)
|
||||
if (!args[0]->IsString()) {
|
||||
JSTHROW("getMat takes a key")
|
||||
}
|
||||
std::string key = std::string(*NanAsciiString(args[0]->ToString()));
|
||||
@ -274,8 +259,7 @@ NAN_METHOD(FaceRecognizerWrap::GetMat){
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im);
|
||||
img->mat = m;
|
||||
|
||||
NanReturnValue( im );
|
||||
NanReturnValue(im);
|
||||
}
|
||||
|
||||
|
||||
#endif // End version > 2.4
|
||||
|
||||
@ -1,41 +1,38 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
#include "opencv2/contrib/contrib.hpp"
|
||||
|
||||
class FaceRecognizerWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::Ptr<cv::FaceRecognizer> rec;
|
||||
int typ;
|
||||
public:
|
||||
cv::Ptr<cv::FaceRecognizer> rec;
|
||||
int typ;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f, int type);
|
||||
FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f, int type);
|
||||
|
||||
JSFUNC(CreateLBPH)
|
||||
JSFUNC(CreateEigen)
|
||||
JSFUNC(CreateFisher)
|
||||
|
||||
JSFUNC(TrainSync)
|
||||
//JSFUNC(Train)
|
||||
JSFUNC(UpdateSync)
|
||||
//JSFUNC(Update)
|
||||
|
||||
JSFUNC(PredictSync)
|
||||
// JSFUNC(Predict)
|
||||
//static void EIO_Predict(eio_req *req);
|
||||
//static int EIO_AfterPredict(eio_req *req);
|
||||
JSFUNC(CreateLBPH)
|
||||
JSFUNC(CreateEigen)
|
||||
JSFUNC(CreateFisher)
|
||||
|
||||
JSFUNC(TrainSync)
|
||||
//JSFUNC(Train)
|
||||
JSFUNC(UpdateSync)
|
||||
//JSFUNC(Update)
|
||||
|
||||
JSFUNC(SaveSync)
|
||||
JSFUNC(LoadSync)
|
||||
|
||||
JSFUNC(GetMat)
|
||||
JSFUNC(PredictSync)
|
||||
// JSFUNC(Predict)
|
||||
//static void EIO_Predict(eio_req *req);
|
||||
//static int EIO_AfterPredict(eio_req *req);
|
||||
|
||||
JSFUNC(SaveSync)
|
||||
JSFUNC(LoadSync)
|
||||
|
||||
JSFUNC(GetMat)
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -3,72 +3,83 @@
|
||||
#include <nan.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
void
|
||||
Features::Init(Handle<Object> target) {
|
||||
void Features::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
NODE_SET_METHOD(target, "ImageSimilarity", Similarity);
|
||||
};
|
||||
|
||||
class AsyncDetectSimilarity : public NanAsyncWorker {
|
||||
public:
|
||||
AsyncDetectSimilarity(NanCallback *callback, cv::Mat image1, cv::Mat image2) : NanAsyncWorker(callback), image1(image1), image2(image2), dissimilarity(0) {}
|
||||
~AsyncDetectSimilarity() {}
|
||||
|
||||
void Execute () {
|
||||
|
||||
cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create("ORB");
|
||||
cv::Ptr<cv::DescriptorExtractor> extractor = cv::DescriptorExtractor::create("ORB");
|
||||
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
|
||||
|
||||
std::vector<cv::DMatch> matches;
|
||||
|
||||
cv::Mat descriptors1 = cv::Mat();
|
||||
cv::Mat descriptors2 = cv::Mat();
|
||||
|
||||
std::vector<cv::KeyPoint> keypoints1;
|
||||
std::vector<cv::KeyPoint> keypoints2;
|
||||
|
||||
detector->detect(image1, keypoints1);
|
||||
detector->detect(image2, keypoints2);
|
||||
|
||||
extractor->compute(image1, keypoints1, descriptors1);
|
||||
extractor->compute(image2, keypoints2, descriptors2);
|
||||
|
||||
matcher->match(descriptors1, descriptors2, matches);
|
||||
|
||||
double max_dist = 0;
|
||||
double min_dist = 100;
|
||||
|
||||
//-- Quick calculation of max and min distances between keypoints
|
||||
for (int i = 0; i < descriptors1.rows; i++) {
|
||||
double dist = matches[i].distance;
|
||||
if( dist < min_dist ) min_dist = dist;
|
||||
if( dist > max_dist ) max_dist = dist;
|
||||
}
|
||||
|
||||
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
|
||||
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
|
||||
//-- small)
|
||||
//-- PS.- radiusMatch can also be used here.
|
||||
std::vector<cv::DMatch> good_matches;
|
||||
double good_matches_sum = 0.0;
|
||||
|
||||
for (int i = 0; i < descriptors1.rows; i++ ) {
|
||||
double distance = matches[i].distance;
|
||||
if (distance <= std::max(2*min_dist, 0.02)) {
|
||||
good_matches.push_back(matches[i]);
|
||||
good_matches_sum += distance;
|
||||
}
|
||||
}
|
||||
|
||||
dissimilarity = (double)good_matches_sum / (double)good_matches.size();
|
||||
}
|
||||
|
||||
class AsyncDetectSimilarity: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncDetectSimilarity(NanCallback *callback, cv::Mat image1, cv::Mat image2) :
|
||||
NanAsyncWorker(callback),
|
||||
image1(image1),
|
||||
image2(image2),
|
||||
dissimilarity(0) {
|
||||
}
|
||||
|
||||
void HandleOKCallback () {
|
||||
~AsyncDetectSimilarity() {
|
||||
}
|
||||
|
||||
void Execute() {
|
||||
|
||||
cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create("ORB");
|
||||
cv::Ptr<cv::DescriptorExtractor> extractor =
|
||||
cv::DescriptorExtractor::create("ORB");
|
||||
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create(
|
||||
"BruteForce-Hamming");
|
||||
|
||||
std::vector<cv::DMatch> matches;
|
||||
|
||||
cv::Mat descriptors1 = cv::Mat();
|
||||
cv::Mat descriptors2 = cv::Mat();
|
||||
|
||||
std::vector<cv::KeyPoint> keypoints1;
|
||||
std::vector<cv::KeyPoint> keypoints2;
|
||||
|
||||
detector->detect(image1, keypoints1);
|
||||
detector->detect(image2, keypoints2);
|
||||
|
||||
extractor->compute(image1, keypoints1, descriptors1);
|
||||
extractor->compute(image2, keypoints2, descriptors2);
|
||||
|
||||
matcher->match(descriptors1, descriptors2, matches);
|
||||
|
||||
double max_dist = 0;
|
||||
double min_dist = 100;
|
||||
|
||||
//-- Quick calculation of max and min distances between keypoints
|
||||
for (int i = 0; i < descriptors1.rows; i++) {
|
||||
double dist = matches[i].distance;
|
||||
if (dist < min_dist) {
|
||||
min_dist = dist;
|
||||
}
|
||||
if (dist > max_dist) {
|
||||
max_dist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
|
||||
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
|
||||
//-- small)
|
||||
//-- PS.- radiusMatch can also be used here.
|
||||
std::vector<cv::DMatch> good_matches;
|
||||
double good_matches_sum = 0.0;
|
||||
|
||||
for (int i = 0; i < descriptors1.rows; i++) {
|
||||
double distance = matches[i].distance;
|
||||
if (distance <= std::max(2 * min_dist, 0.02)) {
|
||||
good_matches.push_back(matches[i]);
|
||||
good_matches_sum += distance;
|
||||
}
|
||||
}
|
||||
|
||||
dissimilarity = (double) good_matches_sum / (double) good_matches.size();
|
||||
}
|
||||
|
||||
void HandleOKCallback() {
|
||||
NanScope();
|
||||
|
||||
Handle<Value> argv[2];
|
||||
@ -77,14 +88,12 @@ class AsyncDetectSimilarity : public NanAsyncWorker {
|
||||
argv[1] = NanNew<Number>(dissimilarity);
|
||||
|
||||
callback->Call(2, argv);
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
cv::Mat image1;
|
||||
cv::Mat image2;
|
||||
double dissimilarity;
|
||||
|
||||
private:
|
||||
cv::Mat image1;
|
||||
cv::Mat image2;
|
||||
double dissimilarity;
|
||||
};
|
||||
|
||||
NAN_METHOD(Features::Similarity) {
|
||||
@ -99,7 +108,6 @@ NAN_METHOD(Features::Similarity) {
|
||||
|
||||
NanAsyncQueueWorker( new AsyncDetectSimilarity(callback, image1, image2) );
|
||||
NanReturnUndefined();
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
|
||||
class Features: public node::ObjectWrap {
|
||||
public:
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
public:
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
static NAN_METHOD(Similarity);
|
||||
static NAN_METHOD(Similarity);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,89 +2,83 @@
|
||||
#include "OpenCV.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
|
||||
Persistent<FunctionTemplate> NamedWindow::constructor;
|
||||
|
||||
void
|
||||
NamedWindow::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void NamedWindow::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(NamedWindow::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("NamedWindow"));
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(NamedWindow::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("NamedWindow"));
|
||||
|
||||
// Prototype
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "show", Show);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "destroy", Destroy);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "blockingWaitKey", BlockingWaitKey);
|
||||
|
||||
target->Set(NanNew("NamedWindow"), ctor->GetFunction());
|
||||
// Prototype
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "show", Show);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "destroy", Destroy);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "blockingWaitKey", BlockingWaitKey);
|
||||
|
||||
target->Set(NanNew("NamedWindow"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
|
||||
NAN_METHOD(NamedWindow::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0){
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||
}
|
||||
|
||||
NamedWindow* win;
|
||||
if (args.Length() == 1){
|
||||
win = new NamedWindow(std::string(*NanAsciiString(args[0]->ToString())), 0);
|
||||
} else { //if (args.Length() == 2){
|
||||
win = new NamedWindow(std::string(*NanAsciiString(args[0]->ToString())), 0);
|
||||
if (args.Length() == 1) {
|
||||
win = new NamedWindow(std::string(*NanAsciiString(args[0]->ToString())), 0);
|
||||
} else { //if (args.Length() == 2){
|
||||
win = new NamedWindow(std::string(*NanAsciiString(args[0]->ToString())), 0);
|
||||
}
|
||||
|
||||
win->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
win->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
|
||||
NamedWindow::NamedWindow(const std::string& name, int f){
|
||||
NamedWindow::NamedWindow(const std::string& name, int f) {
|
||||
winname = std::string(name);
|
||||
flags = f;
|
||||
cv::namedWindow(winname, flags);
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(NamedWindow::Show){
|
||||
SETUP_FUNCTION(NamedWindow)
|
||||
NAN_METHOD(NamedWindow::Show) {
|
||||
SETUP_FUNCTION(NamedWindow)
|
||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
|
||||
try{
|
||||
try {
|
||||
cv::imshow(self->winname, im->mat);
|
||||
} catch(cv::Exception& e ){
|
||||
} catch (cv::Exception& e) {
|
||||
const char* err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
}
|
||||
|
||||
NanReturnValue(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
NAN_METHOD(NamedWindow::Destroy){
|
||||
SETUP_FUNCTION(NamedWindow)
|
||||
NAN_METHOD(NamedWindow::Destroy) {
|
||||
SETUP_FUNCTION(NamedWindow)
|
||||
cv::destroyWindow(self->winname);
|
||||
NanReturnValue(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(NamedWindow::BlockingWaitKey){
|
||||
NAN_METHOD(NamedWindow::BlockingWaitKey) {
|
||||
NanScope();
|
||||
//SETUP_FUNCTION(NamedWindow)
|
||||
int time = 0;
|
||||
//SETUP_FUNCTION(NamedWindow)
|
||||
int time = 0;
|
||||
|
||||
if (args.Length() > 1){
|
||||
if (args.Length() > 1) {
|
||||
time = args[1]->IntegerValue();
|
||||
}else{
|
||||
if (args.Length() > 0){
|
||||
} else {
|
||||
if (args.Length() > 0) {
|
||||
time = args[0]->IntegerValue();
|
||||
}
|
||||
}
|
||||
|
||||
int res = cv::waitKey(time);
|
||||
|
||||
NanReturnValue(NanNew<Number>(res));
|
||||
NanReturnValue(NanNew<Number>(res));
|
||||
}
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
|
||||
class NamedWindow: public node::ObjectWrap {
|
||||
public:
|
||||
std::string winname;
|
||||
int flags;
|
||||
public:
|
||||
std::string winname;
|
||||
int flags;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
NamedWindow(const std::string& winname, int flags);
|
||||
NamedWindow(const std::string& winname, int flags);
|
||||
|
||||
JSFUNC(Show);
|
||||
JSFUNC(Destroy);
|
||||
JSFUNC(BlockingWaitKey);
|
||||
JSFUNC(Show)
|
||||
;JSFUNC(Destroy)
|
||||
;JSFUNC(BlockingWaitKey)
|
||||
;
|
||||
|
||||
};
|
||||
|
||||
250
src/ImgProc.cc
250
src/ImgProc.cc
@ -1,169 +1,159 @@
|
||||
#include "ImgProc.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
void ImgProc::Init(Handle<Object> target)
|
||||
{
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
void ImgProc::Init(Handle<Object> target) {
|
||||
Persistent<Object> inner;
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
NanAssignPersistent(inner, obj);
|
||||
|
||||
NODE_SET_METHOD(obj, "undistort", Undistort);
|
||||
NODE_SET_METHOD(obj, "initUndistortRectifyMap", InitUndistortRectifyMap);
|
||||
NODE_SET_METHOD(obj, "remap", Remap);
|
||||
NODE_SET_METHOD(obj, "undistort", Undistort);
|
||||
NODE_SET_METHOD(obj, "initUndistortRectifyMap", InitUndistortRectifyMap);
|
||||
NODE_SET_METHOD(obj, "remap", Remap);
|
||||
|
||||
target->Set(NanNew("imgproc"), obj);
|
||||
target->Set(NanNew("imgproc"), obj);
|
||||
}
|
||||
|
||||
// cv::undistort
|
||||
NAN_METHOD(ImgProc::Undistort)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(ImgProc::Undistort) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat inputImage = m0->mat;
|
||||
// Arg 0 is the image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat inputImage = m0->mat;
|
||||
|
||||
// Arg 1 is the camera matrix
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat K = m1->mat;
|
||||
// Arg 1 is the camera matrix
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat K = m1->mat;
|
||||
|
||||
// Arg 2 is the distortion coefficents
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat dist = m2->mat;
|
||||
// Arg 2 is the distortion coefficents
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat dist = m2->mat;
|
||||
|
||||
// Make an mat to hold the result image
|
||||
cv::Mat outputImage;
|
||||
// Make an mat to hold the result image
|
||||
cv::Mat outputImage;
|
||||
|
||||
// Undistort
|
||||
cv::undistort(inputImage, outputImage, K, dist);
|
||||
// Undistort
|
||||
cv::undistort(inputImage, outputImage, K, dist);
|
||||
|
||||
// Wrap the output image
|
||||
Local<Object> outMatrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
outMatrix->mat = outputImage;
|
||||
// Wrap the output image
|
||||
Local<Object> outMatrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
outMatrix->mat = outputImage;
|
||||
|
||||
// Return the output image
|
||||
NanReturnValue(outMatrixWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
// Return the output image
|
||||
NanReturnValue(outMatrixWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::initUndistortRectifyMap
|
||||
NAN_METHOD(ImgProc::InitUndistortRectifyMap)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(ImgProc::InitUndistortRectifyMap) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
try {
|
||||
// Arg 0 is the camera matrix
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat K = m0->mat;
|
||||
|
||||
// Arg 0 is the camera matrix
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat K = m0->mat;
|
||||
// Arg 1 is the distortion coefficents
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat dist = m1->mat;
|
||||
|
||||
// Arg 1 is the distortion coefficents
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat dist = m1->mat;
|
||||
// Arg 2 is the recification transformation
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat R = m2->mat;
|
||||
|
||||
// Arg 2 is the recification transformation
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat R = m2->mat;
|
||||
// Arg 3 is the new camera matrix
|
||||
Matrix* m3 = ObjectWrap::Unwrap<Matrix>(args[3]->ToObject());
|
||||
cv::Mat newK = m3->mat;
|
||||
|
||||
// Arg 3 is the new camera matrix
|
||||
Matrix* m3 = ObjectWrap::Unwrap<Matrix>(args[3]->ToObject());
|
||||
cv::Mat newK = m3->mat;
|
||||
|
||||
// Arg 4 is the image size
|
||||
cv::Size imageSize;
|
||||
if (args[4]->IsArray()) {
|
||||
Local<Object> v8sz = args[4]->ToObject();
|
||||
|
||||
imageSize = cv::Size(v8sz->Get(1)->IntegerValue(), v8sz->Get(0)->IntegerValue());
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass image size");
|
||||
}
|
||||
|
||||
// Arg 5 is the first map type, skip for now
|
||||
int m1type = args[5]->IntegerValue();
|
||||
|
||||
// Make matrices to hold the output maps
|
||||
cv::Mat map1, map2;
|
||||
|
||||
// Compute the rectification map
|
||||
cv::initUndistortRectifyMap(K, dist, R, newK, imageSize, m1type, map1, map2);
|
||||
|
||||
// Wrap the output maps
|
||||
Local<Object> map1Wrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map1Matrix = ObjectWrap::Unwrap<Matrix>(map1Wrap);
|
||||
map1Matrix->mat = map1;
|
||||
|
||||
Local<Object> map2Wrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map2Matrix = ObjectWrap::Unwrap<Matrix>(map2Wrap);
|
||||
map2Matrix->mat = map2;
|
||||
|
||||
// Make a return object with the two maps
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
ret->Set(NanNew<String>("map1"), map1Wrap);
|
||||
ret->Set(NanNew<String>("map2"), map2Wrap);
|
||||
|
||||
// Return the maps
|
||||
NanReturnValue(ret);
|
||||
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
// Arg 4 is the image size
|
||||
cv::Size imageSize;
|
||||
if (args[4]->IsArray()) {
|
||||
Local<Object> v8sz = args[4]->ToObject();
|
||||
imageSize = cv::Size(v8sz->Get(1)->IntegerValue(), v8sz->Get(0)->IntegerValue());
|
||||
} else {
|
||||
JSTHROW_TYPE("Must pass image size");
|
||||
}
|
||||
|
||||
// Arg 5 is the first map type, skip for now
|
||||
int m1type = args[5]->IntegerValue();
|
||||
|
||||
// Make matrices to hold the output maps
|
||||
cv::Mat map1, map2;
|
||||
|
||||
// Compute the rectification map
|
||||
cv::initUndistortRectifyMap(K, dist, R, newK, imageSize, m1type, map1, map2);
|
||||
|
||||
// Wrap the output maps
|
||||
Local<Object> map1Wrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map1Matrix = ObjectWrap::Unwrap<Matrix>(map1Wrap);
|
||||
map1Matrix->mat = map1;
|
||||
|
||||
Local<Object> map2Wrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *map2Matrix = ObjectWrap::Unwrap<Matrix>(map2Wrap);
|
||||
map2Matrix->mat = map2;
|
||||
|
||||
// Make a return object with the two maps
|
||||
Local<Object> ret = NanNew<Object>();
|
||||
ret->Set(NanNew<String>("map1"), map1Wrap);
|
||||
ret->Set(NanNew<String>("map2"), map2Wrap);
|
||||
|
||||
// Return the maps
|
||||
NanReturnValue(ret);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// cv::remap
|
||||
NAN_METHOD(ImgProc::Remap)
|
||||
{
|
||||
NanEscapableScope();
|
||||
NAN_METHOD(ImgProc::Remap) {
|
||||
NanEscapableScope();
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0 is the image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat inputImage = m0->mat;
|
||||
// Arg 0 is the image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat inputImage = m0->mat;
|
||||
|
||||
// Arg 1 is the first map
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat map1 = m1->mat;
|
||||
// Arg 1 is the first map
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat map1 = m1->mat;
|
||||
|
||||
// Arg 2 is the second map
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat map2 = m2->mat;
|
||||
// Arg 2 is the second map
|
||||
Matrix* m2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
cv::Mat map2 = m2->mat;
|
||||
|
||||
// Arg 3 is the interpolation mode
|
||||
int interpolation = args[3]->IntegerValue();
|
||||
// Arg 3 is the interpolation mode
|
||||
int interpolation = args[3]->IntegerValue();
|
||||
|
||||
// Args 4, 5 border settings, skipping for now
|
||||
// Args 4, 5 border settings, skipping for now
|
||||
|
||||
// Output image
|
||||
cv::Mat outputImage;
|
||||
// Output image
|
||||
cv::Mat outputImage;
|
||||
|
||||
// Remap
|
||||
cv::remap(inputImage, outputImage, map1, map2, interpolation);
|
||||
// Remap
|
||||
cv::remap(inputImage, outputImage, map1, map2, interpolation);
|
||||
|
||||
// Wrap the output image
|
||||
Local<Object> outMatrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
outMatrix->mat = outputImage;
|
||||
// Wrap the output image
|
||||
Local<Object> outMatrixWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *outMatrix = ObjectWrap::Unwrap<Matrix>(outMatrixWrap);
|
||||
outMatrix->mat = outputImage;
|
||||
|
||||
// Return the image
|
||||
NanReturnValue(outMatrixWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
// Return the image
|
||||
NanReturnValue(outMatrixWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
|
||||
#include "OpenCV.h"
|
||||
|
||||
// Implementation of imgproc.hpp functions
|
||||
|
||||
/**
|
||||
* Implementation of imgproc.hpp functions
|
||||
*/
|
||||
class ImgProc: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
static NAN_METHOD(Undistort);
|
||||
|
||||
static NAN_METHOD(InitUndistortRectifyMap);
|
||||
|
||||
static NAN_METHOD(Remap);
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(Undistort);
|
||||
static NAN_METHOD(InitUndistortRectifyMap);
|
||||
static NAN_METHOD(Remap);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
2125
src/Matrix.cc
2125
src/Matrix.cc
File diff suppressed because it is too large
Load Diff
249
src/Matrix.h
249
src/Matrix.h
@ -1,153 +1,152 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Matrix: public node::ObjectWrap {
|
||||
public:
|
||||
public:
|
||||
|
||||
cv::Mat mat;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
Matrix();
|
||||
Matrix(cv::Mat other, cv::Rect roi);
|
||||
Matrix(int rows, int cols);
|
||||
Matrix(int rows, int cols, int type);
|
||||
Matrix(int rows, int cols, int type, Local<Object> scalarObj);
|
||||
cv::Mat mat;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
Matrix();
|
||||
Matrix(cv::Mat other, cv::Rect roi);
|
||||
Matrix(int rows, int cols);
|
||||
Matrix(int rows, int cols, int type);
|
||||
Matrix(int rows, int cols, int type, Local<Object> scalarObj);
|
||||
|
||||
static double DblGet(cv::Mat mat, int i, int j);
|
||||
static double DblGet(cv::Mat mat, int i, int j);
|
||||
|
||||
JSFUNC(Zeros) // factory
|
||||
JSFUNC(Ones) // factory
|
||||
JSFUNC(Eye) // factory
|
||||
JSFUNC(Zeros) // factory
|
||||
JSFUNC(Ones) // factory
|
||||
JSFUNC(Eye) // factory
|
||||
|
||||
JSFUNC(Get) // at
|
||||
JSFUNC(Set)
|
||||
JSFUNC(Put)
|
||||
JSFUNC(Get) // at
|
||||
JSFUNC(Set)
|
||||
JSFUNC(Put)
|
||||
|
||||
JSFUNC(GetData)
|
||||
JSFUNC(Normalize)
|
||||
JSFUNC(Brightness)
|
||||
JSFUNC(GetData)
|
||||
JSFUNC(Normalize)
|
||||
JSFUNC(Brightness)
|
||||
|
||||
JSFUNC(Row)
|
||||
JSFUNC(PixelRow)
|
||||
JSFUNC(Col)
|
||||
JSFUNC(PixelCol)
|
||||
JSFUNC(Row)
|
||||
JSFUNC(PixelRow)
|
||||
JSFUNC(Col)
|
||||
JSFUNC(PixelCol)
|
||||
|
||||
JSFUNC(Size)
|
||||
JSFUNC(Width)
|
||||
JSFUNC(Height)
|
||||
JSFUNC(Channels)
|
||||
JSFUNC(Clone)
|
||||
JSFUNC(Ellipse)
|
||||
JSFUNC(Rectangle)
|
||||
JSFUNC(Line)
|
||||
JSFUNC(Empty)
|
||||
JSFUNC(FillPoly)
|
||||
JSFUNC(Size)
|
||||
JSFUNC(Width)
|
||||
JSFUNC(Height)
|
||||
JSFUNC(Channels)
|
||||
JSFUNC(Clone)
|
||||
JSFUNC(Ellipse)
|
||||
JSFUNC(Rectangle)
|
||||
JSFUNC(Line)
|
||||
JSFUNC(Empty)
|
||||
JSFUNC(FillPoly)
|
||||
|
||||
JSFUNC(Save)
|
||||
JSFUNC(SaveAsync)
|
||||
JSFUNC(Save)
|
||||
JSFUNC(SaveAsync)
|
||||
|
||||
JSFUNC(ToBuffer)
|
||||
JSFUNC(ToBufferAsync)
|
||||
JSFUNC(ToBuffer)
|
||||
JSFUNC(ToBufferAsync)
|
||||
|
||||
JSFUNC(Resize)
|
||||
JSFUNC(Rotate)
|
||||
JSFUNC(PyrDown)
|
||||
JSFUNC(PyrUp)
|
||||
JSFUNC(Resize)
|
||||
JSFUNC(Rotate)
|
||||
JSFUNC(PyrDown)
|
||||
JSFUNC(PyrUp)
|
||||
|
||||
JSFUNC(ConvertGrayscale)
|
||||
JSFUNC(ConvertHSVscale)
|
||||
JSFUNC(GaussianBlur)
|
||||
JSFUNC(MedianBlur)
|
||||
JSFUNC(BilateralFilter)
|
||||
JSFUNC(Copy)
|
||||
JSFUNC(Flip)
|
||||
JSFUNC(ROI)
|
||||
JSFUNC(Ptr)
|
||||
JSFUNC(AbsDiff)
|
||||
JSFUNC(AddWeighted)
|
||||
JSFUNC(BitwiseXor)
|
||||
JSFUNC(BitwiseNot)
|
||||
JSFUNC(BitwiseAnd)
|
||||
JSFUNC(CountNonZero)
|
||||
//JSFUNC(Split)
|
||||
JSFUNC(Canny)
|
||||
JSFUNC(Dilate)
|
||||
JSFUNC(Erode)
|
||||
JSFUNC(ConvertGrayscale)
|
||||
JSFUNC(ConvertHSVscale)
|
||||
JSFUNC(GaussianBlur)
|
||||
JSFUNC(MedianBlur)
|
||||
JSFUNC(BilateralFilter)
|
||||
JSFUNC(Copy)
|
||||
JSFUNC(Flip)
|
||||
JSFUNC(ROI)
|
||||
JSFUNC(Ptr)
|
||||
JSFUNC(AbsDiff)
|
||||
JSFUNC(AddWeighted)
|
||||
JSFUNC(BitwiseXor)
|
||||
JSFUNC(BitwiseNot)
|
||||
JSFUNC(BitwiseAnd)
|
||||
JSFUNC(CountNonZero)
|
||||
//JSFUNC(Split)
|
||||
JSFUNC(Canny)
|
||||
JSFUNC(Dilate)
|
||||
JSFUNC(Erode)
|
||||
|
||||
JSFUNC(FindContours)
|
||||
JSFUNC(DrawContour)
|
||||
JSFUNC(DrawAllContours)
|
||||
JSFUNC(FindContours)
|
||||
JSFUNC(DrawContour)
|
||||
JSFUNC(DrawAllContours)
|
||||
|
||||
// Feature Detection
|
||||
JSFUNC(GoodFeaturesToTrack)
|
||||
JSFUNC(HoughLinesP)
|
||||
JSFUNC(HoughCircles)
|
||||
// Feature Detection
|
||||
JSFUNC(GoodFeaturesToTrack)
|
||||
JSFUNC(HoughLinesP)
|
||||
JSFUNC(HoughCircles)
|
||||
|
||||
JSFUNC(Crop)
|
||||
JSFUNC(Crop)
|
||||
|
||||
JSFUNC(inRange)
|
||||
JSFUNC(inRange)
|
||||
|
||||
JSFUNC(LocateROI)
|
||||
JSFUNC(AdjustROI)
|
||||
JSFUNC(LocateROI)
|
||||
JSFUNC(AdjustROI)
|
||||
|
||||
JSFUNC(Threshold)
|
||||
JSFUNC(AdaptiveThreshold)
|
||||
JSFUNC(MeanStdDev)
|
||||
JSFUNC(Threshold)
|
||||
JSFUNC(AdaptiveThreshold)
|
||||
JSFUNC(MeanStdDev)
|
||||
|
||||
JSFUNC(CopyTo)
|
||||
JSFUNC(CvtColor)
|
||||
JSFUNC(Split)
|
||||
JSFUNC(Merge)
|
||||
JSFUNC(EqualizeHist)
|
||||
JSFUNC(Pixel)
|
||||
JSFUNC(FloodFill)
|
||||
JSFUNC(CopyTo)
|
||||
JSFUNC(CvtColor)
|
||||
JSFUNC(Split)
|
||||
JSFUNC(Merge)
|
||||
JSFUNC(EqualizeHist)
|
||||
JSFUNC(Pixel)
|
||||
JSFUNC(FloodFill)
|
||||
|
||||
JSFUNC(MatchTemplate)
|
||||
JSFUNC(TemplateMatches)
|
||||
JSFUNC(MinMaxLoc)
|
||||
JSFUNC(MatchTemplate)
|
||||
JSFUNC(TemplateMatches)
|
||||
JSFUNC(MinMaxLoc)
|
||||
|
||||
JSFUNC(PushBack)
|
||||
JSFUNC(PushBack)
|
||||
|
||||
JSFUNC(PutText)
|
||||
JSFUNC(GetPerspectiveTransform)
|
||||
JSFUNC(WarpPerspective)
|
||||
JSFUNC(PutText)
|
||||
JSFUNC(GetPerspectiveTransform)
|
||||
JSFUNC(WarpPerspective)
|
||||
|
||||
JSFUNC(CopyWithMask)
|
||||
JSFUNC(SetWithMask)
|
||||
JSFUNC(MeanWithMask)
|
||||
JSFUNC(Shift)
|
||||
JSFUNC(CopyWithMask)
|
||||
JSFUNC(SetWithMask)
|
||||
JSFUNC(MeanWithMask)
|
||||
JSFUNC(Shift)
|
||||
|
||||
JSFUNC(Release)
|
||||
/*
|
||||
static Handle<Value> Val(const Arguments& args);
|
||||
static Handle<Value> RowRange(const Arguments& args);
|
||||
static Handle<Value> ColRange(const Arguments& args);
|
||||
static Handle<Value> Diag(const Arguments& args);
|
||||
static Handle<Value> Clone(const Arguments& args);
|
||||
static Handle<Value> CopyTo(const Arguments& args);
|
||||
static Handle<Value> ConvertTo(const Arguments& args);
|
||||
static Handle<Value> AssignTo(const Arguments& args);
|
||||
static Handle<Value> SetTo(const Arguments& args);
|
||||
static Handle<Value> Reshape(const Arguments& args);
|
||||
static Handle<Value> Transpose(const Arguments& args);
|
||||
static Handle<Value> Invert(const Arguments& args);
|
||||
static Handle<Value> Multiply(const Arguments& args);
|
||||
static Handle<Value> Cross(const Arguments& args);
|
||||
static Handle<Value> Dot(const Arguments& args);
|
||||
static Handle<Value> Zeroes(const Arguments& args);
|
||||
static Handle<Value> Ones(const Arguments& args);
|
||||
// create, increment, release
|
||||
static Handle<Value> PushBack(const Arguments& args);
|
||||
static Handle<Value> PopBack(const Arguments& args);
|
||||
static Handle<Value> Total(const Arguments& args);
|
||||
static Handle<Value> IsContinous(const Arguments& args);
|
||||
static Handle<Value> Type(const Arguments& args);
|
||||
static Handle<Value> Depth(const Arguments& args);
|
||||
static Handle<Value> Channels(const Arguments& args);
|
||||
static Handle<Value> StepOne(const Arguments& args);
|
||||
static Handle<Value> GetPerspectiveTransform(const Arguments& args);
|
||||
static Handle<Value> WarpPerspective(const Arguments& args);
|
||||
|
||||
*/
|
||||
JSFUNC(Release)
|
||||
/*
|
||||
static Handle<Value> Val(const Arguments& args);
|
||||
static Handle<Value> RowRange(const Arguments& args);
|
||||
static Handle<Value> ColRange(const Arguments& args);
|
||||
static Handle<Value> Diag(const Arguments& args);
|
||||
static Handle<Value> Clone(const Arguments& args);
|
||||
static Handle<Value> CopyTo(const Arguments& args);
|
||||
static Handle<Value> ConvertTo(const Arguments& args);
|
||||
static Handle<Value> AssignTo(const Arguments& args);
|
||||
static Handle<Value> SetTo(const Arguments& args);
|
||||
static Handle<Value> Reshape(const Arguments& args);
|
||||
static Handle<Value> Transpose(const Arguments& args);
|
||||
static Handle<Value> Invert(const Arguments& args);
|
||||
static Handle<Value> Multiply(const Arguments& args);
|
||||
static Handle<Value> Cross(const Arguments& args);
|
||||
static Handle<Value> Dot(const Arguments& args);
|
||||
static Handle<Value> Zeroes(const Arguments& args);
|
||||
static Handle<Value> Ones(const Arguments& args);
|
||||
// create, increment, release
|
||||
static Handle<Value> PushBack(const Arguments& args);
|
||||
static Handle<Value> PopBack(const Arguments& args);
|
||||
static Handle<Value> Total(const Arguments& args);
|
||||
static Handle<Value> IsContinous(const Arguments& args);
|
||||
static Handle<Value> Type(const Arguments& args);
|
||||
static Handle<Value> Depth(const Arguments& args);
|
||||
static Handle<Value> Channels(const Arguments& args);
|
||||
static Handle<Value> StepOne(const Arguments& args);
|
||||
static Handle<Value> GetPerspectiveTransform(const Arguments& args);
|
||||
static Handle<Value> WarpPerspective(const Arguments& args);
|
||||
|
||||
*/
|
||||
};
|
||||
|
||||
@ -2,8 +2,7 @@
|
||||
#include "Matrix.h"
|
||||
#include <nan.h>
|
||||
|
||||
void
|
||||
OpenCV::Init(Handle<Object> target) {
|
||||
void OpenCV::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
// Version string.
|
||||
@ -14,25 +13,22 @@ OpenCV::Init(Handle<Object> target) {
|
||||
NODE_SET_METHOD(target, "readImage", ReadImage);
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(OpenCV::ReadImage) {
|
||||
NanEscapableScope();
|
||||
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
Local<Value> argv[2];
|
||||
|
||||
argv[0] = NanNull();
|
||||
|
||||
Local<Object> im_h = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
argv[1] = im_h;
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
cv::Mat mat;
|
||||
|
||||
if (args[0]->IsNumber() && args[1]->IsNumber()){
|
||||
if (args[0]->IsNumber() && args[1]->IsNumber()) {
|
||||
int width, height;
|
||||
|
||||
width = args[0]->Uint32Value();
|
||||
@ -40,31 +36,28 @@ NAN_METHOD(OpenCV::ReadImage) {
|
||||
mat = *(new cv::Mat(width, height, CV_64FC1));
|
||||
|
||||
} else if (args[0]->IsString()) {
|
||||
|
||||
std::string filename = std::string(*NanUtf8String(args[0]->ToString()));
|
||||
mat = cv::imread(filename);
|
||||
|
||||
} else if (Buffer::HasInstance(args[0])){
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||
unsigned len = Buffer::Length(args[0]->ToObject());
|
||||
} else if (Buffer::HasInstance(args[0])) {
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||
unsigned len = Buffer::Length(args[0]->ToObject());
|
||||
|
||||
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
|
||||
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
|
||||
mat = cv::imdecode(*mbuf, -1);
|
||||
|
||||
if (mat.empty()){
|
||||
if (mat.empty()) {
|
||||
argv[0] = NanError("Error loading file");
|
||||
}
|
||||
}
|
||||
|
||||
img->mat = mat;
|
||||
|
||||
} catch( cv::Exception& e ){
|
||||
argv[0] = NanError(e.what());
|
||||
argv[1] = NanNull();
|
||||
} catch (cv::Exception& e) {
|
||||
argv[0] = NanError(e.what());
|
||||
argv[1] = NanNull();
|
||||
}
|
||||
|
||||
TryCatch try_catch;
|
||||
|
||||
cb->Call(NanGetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
@ -72,4 +65,4 @@ NAN_METHOD(OpenCV::ReadImage) {
|
||||
}
|
||||
|
||||
NanReturnUndefined();
|
||||
};
|
||||
}
|
||||
|
||||
13
src/OpenCV.h
13
src/OpenCV.h
@ -19,7 +19,6 @@ using namespace node;
|
||||
return NanThrowTypeError("Argument " #I " must be a function"); \
|
||||
Local<Function> VAR = Local<Function>::Cast(args[I]);
|
||||
|
||||
|
||||
#define SETUP_FUNCTION(TYP) \
|
||||
NanScope(); \
|
||||
TYP *self = ObjectWrap::Unwrap<TYP>(args.This());
|
||||
@ -30,11 +29,9 @@ using namespace node;
|
||||
#define JSTHROW_TYPE(ERR) \
|
||||
NanThrowTypeError( ERR );
|
||||
|
||||
|
||||
#define JSTHROW(ERR) \
|
||||
NanThrowError( ERR );
|
||||
|
||||
|
||||
#define INT_FROM_ARGS(NAME, IND) \
|
||||
if (args[IND]->IsInt32()){ \
|
||||
NAME = args[IND]->Uint32Value(); \
|
||||
@ -45,13 +42,11 @@ using namespace node;
|
||||
NAME = args[IND]->NumberValue(); \
|
||||
}
|
||||
|
||||
class OpenCV: public node::ObjectWrap{
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
class OpenCV: public node::ObjectWrap {
|
||||
public:
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
static NAN_METHOD(ReadImage);
|
||||
static NAN_METHOD(ReadImage);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
61
src/Point.cc
61
src/Point.cc
@ -3,60 +3,61 @@
|
||||
|
||||
v8::Persistent<FunctionTemplate> Point::constructor;
|
||||
|
||||
void Point::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
void
|
||||
Point::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Point::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("Point"));
|
||||
|
||||
// Constructor
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Point::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("Point"));
|
||||
|
||||
// Prototype
|
||||
Local<ObjectTemplate> proto = ctor->PrototypeTemplate();
|
||||
proto->SetAccessor(NanNew("x"), GetX, RaiseImmutable);
|
||||
proto->SetAccessor(NanNew("y"), GetY, RaiseImmutable);
|
||||
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "dot", Dot);
|
||||
// Prototype
|
||||
Local<ObjectTemplate> proto = ctor->PrototypeTemplate();
|
||||
proto->SetAccessor(NanNew("x"), GetX, RaiseImmutable);
|
||||
proto->SetAccessor(NanNew("y"), GetY, RaiseImmutable);
|
||||
|
||||
target->Set(NanNew("Point"), ctor->GetFunction());
|
||||
};
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "dot", Dot);
|
||||
|
||||
target->Set(NanNew("Point"), ctor->GetFunction());
|
||||
};
|
||||
|
||||
NAN_METHOD(Point::New) {
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
return NanThrowTypeError("Cannot Instantiate without new");
|
||||
}
|
||||
|
||||
double x = 0, y = 0;
|
||||
if (args[0]->IsNumber()) x = args[0]->NumberValue();
|
||||
if (args[1]->IsNumber()) y = args[1]->NumberValue();
|
||||
Point *pt = new Point(x, y);
|
||||
if (args[0]->IsNumber()) {
|
||||
x = args[0]->NumberValue();
|
||||
}
|
||||
if (args[1]->IsNumber()) {
|
||||
y = args[1]->NumberValue();
|
||||
}
|
||||
Point *pt = new Point(x, y);
|
||||
pt->Wrap(args.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
NAN_GETTER(Point::GetX){
|
||||
NAN_GETTER(Point::GetX) {
|
||||
NanScope();
|
||||
Point *pt = ObjectWrap::Unwrap<Point>(args.This());
|
||||
NanReturnValue(NanNew<Number>(pt->point.x));
|
||||
}
|
||||
|
||||
NAN_GETTER(Point::GetY){
|
||||
NAN_GETTER(Point::GetY) {
|
||||
NanScope();
|
||||
Point *pt = ObjectWrap::Unwrap<Point>(args.This());
|
||||
NanReturnValue(NanNew<Number>(pt->point.y));
|
||||
}
|
||||
|
||||
|
||||
NAN_SETTER(Point::RaiseImmutable){
|
||||
NAN_SETTER(Point::RaiseImmutable) {
|
||||
NanThrowTypeError("Point is immutable");
|
||||
}
|
||||
|
||||
NAN_METHOD(Point::Dot){
|
||||
NAN_METHOD(Point::Dot) {
|
||||
NanScope();
|
||||
Point *p1 = ObjectWrap::Unwrap<Point>(args.This());
|
||||
Point *p2 = ObjectWrap::Unwrap<Point>(args[0]->ToObject());
|
||||
@ -65,7 +66,7 @@ NAN_METHOD(Point::Dot){
|
||||
NanReturnValue(NanNew<Number>(p1->point.x * p2->point.x + p1->point.y * p2->point.y));
|
||||
}
|
||||
|
||||
|
||||
Point::Point(double x, double y): ObjectWrap() {
|
||||
point = cvPoint2D32f(x, y);
|
||||
Point::Point(double x, double y) :
|
||||
ObjectWrap() {
|
||||
point = cvPoint2D32f(x, y);
|
||||
}
|
||||
|
||||
24
src/Point.h
24
src/Point.h
@ -3,17 +3,17 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class Point: public node::ObjectWrap {
|
||||
public:
|
||||
CvPoint2D32f point;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
Point(double x, double y);
|
||||
|
||||
static NAN_GETTER(GetX);
|
||||
static NAN_GETTER(GetY);
|
||||
static NAN_SETTER(RaiseImmutable);
|
||||
|
||||
static NAN_METHOD(Dot);
|
||||
public:
|
||||
CvPoint2D32f point;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
Point(double x, double y);
|
||||
|
||||
static NAN_GETTER(GetX);
|
||||
static NAN_GETTER(GetY);
|
||||
static NAN_SETTER(RaiseImmutable);
|
||||
|
||||
static NAN_METHOD(Dot);
|
||||
};
|
||||
|
||||
|
||||
465
src/Stereo.cc
465
src/Stereo.cc
@ -6,318 +6,309 @@
|
||||
|
||||
v8::Persistent<FunctionTemplate> StereoBM::constructor;
|
||||
|
||||
void
|
||||
StereoBM::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void StereoBM::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoBM::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("StereoBM"));
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoBM::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("StereoBM"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
|
||||
ctor->Set(NanNew<String>("BASIC_PRESET"), NanNew<Integer>((int)cv::StereoBM::BASIC_PRESET));
|
||||
ctor->Set(NanNew<String>("FISH_EYE_PRESET"), NanNew<Integer>((int)cv::StereoBM::FISH_EYE_PRESET));
|
||||
ctor->Set(NanNew<String>("NARROW_PRESET"), NanNew<Integer>((int)cv::StereoBM::NARROW_PRESET));
|
||||
ctor->Set(NanNew<String>("BASIC_PRESET"), NanNew<Integer>((int)cv::StereoBM::BASIC_PRESET));
|
||||
ctor->Set(NanNew<String>("FISH_EYE_PRESET"), NanNew<Integer>((int)cv::StereoBM::FISH_EYE_PRESET));
|
||||
ctor->Set(NanNew<String>("NARROW_PRESET"), NanNew<Integer>((int)cv::StereoBM::NARROW_PRESET));
|
||||
|
||||
target->Set(NanNew("StereoBM"), ctor->GetFunction());
|
||||
target->Set(NanNew("StereoBM"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(StereoBM::New) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
StereoBM *stereo;
|
||||
StereoBM *stereo;
|
||||
|
||||
if (args.Length() == 0)
|
||||
{
|
||||
stereo = new StereoBM();
|
||||
}
|
||||
else if (args.Length() == 1)
|
||||
{
|
||||
stereo = new StereoBM(args[0]->IntegerValue()); // preset
|
||||
}
|
||||
else if (args.Length() == 2)
|
||||
{
|
||||
stereo = new StereoBM(args[0]->IntegerValue(), args[1]->IntegerValue()); // preset, disparity search range
|
||||
}
|
||||
else
|
||||
{
|
||||
stereo = new StereoBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue()); // preset, disparity search range, sum of absolute differences window size
|
||||
}
|
||||
if (args.Length() == 0) {
|
||||
stereo = new StereoBM();
|
||||
} else if (args.Length() == 1) {
|
||||
// preset
|
||||
stereo = new StereoBM(args[0]->IntegerValue());
|
||||
} else if (args.Length() == 2) {
|
||||
// preset, disparity search range
|
||||
stereo = new StereoBM(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
} else {
|
||||
stereo = new StereoBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
// preset, disparity search range, sum of absolute differences window size
|
||||
args[2]->IntegerValue());
|
||||
}
|
||||
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
StereoBM::StereoBM(int preset, int ndisparities, int SADWindowSize)
|
||||
: ObjectWrap(), stereo(preset, ndisparities, SADWindowSize)
|
||||
{
|
||||
|
||||
StereoBM::StereoBM(int preset, int ndisparities, int SADWindowSize) :
|
||||
ObjectWrap(),
|
||||
stereo(preset, ndisparities, SADWindowSize) {
|
||||
}
|
||||
|
||||
// TODO make this async
|
||||
NAN_METHOD(StereoBM::Compute)
|
||||
{
|
||||
SETUP_FUNCTION(StereoBM)
|
||||
NAN_METHOD(StereoBM::Compute) {
|
||||
SETUP_FUNCTION(StereoBM)
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
|
||||
// Optional 3rd arg, the disparty depth
|
||||
int type = CV_16S;
|
||||
if(args.Length() > 2)
|
||||
{
|
||||
type = args[2]->IntegerValue();
|
||||
}
|
||||
|
||||
// Compute stereo using the block matching algorithm
|
||||
cv::Mat disparity;
|
||||
self->stereo(left, right, disparity, type);
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local<Object> disparityWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
NanReturnValue(disparityWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
// Optional 3rd arg, the disparty depth
|
||||
int type = CV_16S;
|
||||
if (args.Length() > 2) {
|
||||
type = args[2]->IntegerValue();
|
||||
}
|
||||
|
||||
};
|
||||
// Compute stereo using the block matching algorithm
|
||||
cv::Mat disparity;
|
||||
self->stereo(left, right, disparity, type);
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local < Object > disparityWrap =
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
NanReturnValue(disparityWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// Semi-Global Block matching
|
||||
|
||||
v8::Persistent<FunctionTemplate> StereoSGBM::constructor;
|
||||
|
||||
void
|
||||
StereoSGBM::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void StereoSGBM::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoSGBM::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("StereoSGBM"));
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoSGBM::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("StereoSGBM"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
|
||||
target->Set(NanNew("StereoSGBM"), ctor->GetFunction());
|
||||
target->Set(NanNew("StereoSGBM"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(StereoSGBM::New) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0) {
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
}
|
||||
|
||||
StereoSGBM *stereo;
|
||||
StereoSGBM *stereo;
|
||||
|
||||
if (args.Length() == 0)
|
||||
{
|
||||
stereo = new StereoSGBM();
|
||||
if (args.Length() == 0) {
|
||||
stereo = new StereoSGBM();
|
||||
} else {
|
||||
// If passing arguments, must pass the first 3 at least
|
||||
if (args.Length() >= 3) {
|
||||
switch (args.Length()) {
|
||||
case 3:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue());
|
||||
break;
|
||||
case 4:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue());
|
||||
break;
|
||||
case 5:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue());
|
||||
break;
|
||||
case 6:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue());
|
||||
break;
|
||||
case 7:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue());
|
||||
break;
|
||||
case 8:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue());
|
||||
break;
|
||||
case 9:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(),
|
||||
args[8]->IntegerValue());
|
||||
break;
|
||||
case 10:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(),
|
||||
args[8]->IntegerValue(), args[9]->IntegerValue());
|
||||
break;
|
||||
default:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(),
|
||||
args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(),
|
||||
args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(),
|
||||
args[8]->IntegerValue(), args[9]->IntegerValue(), args[10]->ToBoolean()->Value());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
NanThrowError("If overriding default settings, must pass minDisparity, numDisparities, and SADWindowSize");
|
||||
NanReturnUndefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If passing arguments, must pass the first 3 at least
|
||||
if (args.Length() >= 3)
|
||||
{
|
||||
switch (args.Length())
|
||||
{
|
||||
case 3:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue());
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue());
|
||||
break;
|
||||
|
||||
case 5:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue());
|
||||
break;
|
||||
|
||||
case 6:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(), args[5]->IntegerValue());
|
||||
break;
|
||||
|
||||
case 7:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(), args[5]->IntegerValue(), args[6]->IntegerValue());
|
||||
break;
|
||||
|
||||
case 8:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(), args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue());
|
||||
break;
|
||||
|
||||
case 9:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(), args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(), args[8]->IntegerValue());
|
||||
break;
|
||||
|
||||
case 10:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(), args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(), args[8]->IntegerValue(), args[9]->IntegerValue());
|
||||
break;
|
||||
|
||||
default:
|
||||
stereo = new StereoSGBM(args[0]->IntegerValue(), args[1]->IntegerValue(), args[2]->IntegerValue(), args[3]->IntegerValue(), args[4]->IntegerValue(), args[5]->IntegerValue(), args[6]->IntegerValue(), args[7]->IntegerValue(), args[8]->IntegerValue(), args[9]->IntegerValue(), args[10]->ToBoolean()->Value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NanThrowError("If overriding default settings, must pass minDisparity, numDisparities, and SADWindowSize");
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
StereoSGBM::StereoSGBM()
|
||||
: ObjectWrap(), stereo()
|
||||
{
|
||||
StereoSGBM::StereoSGBM() :
|
||||
ObjectWrap(),
|
||||
stereo() {
|
||||
|
||||
}
|
||||
|
||||
StereoSGBM::StereoSGBM(int minDisparity, int ndisparities, int SADWindowSize, int p1, int p2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize, int speckleRange, bool fullDP)
|
||||
: ObjectWrap(), stereo(minDisparity, ndisparities, SADWindowSize, p1, p2, disp12MaxDiff, preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange, fullDP)
|
||||
{
|
||||
|
||||
StereoSGBM::StereoSGBM(int minDisparity, int ndisparities, int SADWindowSize,
|
||||
int p1, int p2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio,
|
||||
int speckleWindowSize, int speckleRange, bool fullDP) :
|
||||
ObjectWrap(),
|
||||
stereo(minDisparity, ndisparities, SADWindowSize, p1, p2, disp12MaxDiff,
|
||||
preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange, fullDP) {
|
||||
}
|
||||
|
||||
// TODO make this async
|
||||
NAN_METHOD(StereoSGBM::Compute)
|
||||
{
|
||||
SETUP_FUNCTION(StereoSGBM)
|
||||
NAN_METHOD(StereoSGBM::Compute) {
|
||||
SETUP_FUNCTION(StereoSGBM)
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
|
||||
// Compute stereo using the block matching algorithm
|
||||
cv::Mat disparity;
|
||||
self->stereo(left, right, disparity);
|
||||
// Compute stereo using the block matching algorithm
|
||||
cv::Mat disparity;
|
||||
self->stereo(left, right, disparity);
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local<Object> disparityWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
// Wrap the returned disparity map
|
||||
Local < Object > disparityWrap =
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
NanReturnValue(disparityWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
};
|
||||
NanReturnValue(disparityWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
// Graph cut
|
||||
|
||||
v8::Persistent<FunctionTemplate> StereoGC::constructor;
|
||||
|
||||
void
|
||||
StereoGC::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
void StereoGC::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoGC::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("StereoGC"));
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(StereoGC::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("StereoGC"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "compute", Compute);
|
||||
|
||||
target->Set(NanNew("StereoGC"), ctor->GetFunction());
|
||||
target->Set(NanNew("StereoGC"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(StereoGC::New) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
NanThrowTypeError("Cannot instantiate without new");
|
||||
|
||||
StereoGC *stereo;
|
||||
StereoGC *stereo;
|
||||
|
||||
if (args.Length() == 0)
|
||||
{
|
||||
stereo = new StereoGC();
|
||||
}
|
||||
else if (args.Length() == 1)
|
||||
{
|
||||
stereo = new StereoGC(args[0]->IntegerValue()); // numberOfDisparities
|
||||
}
|
||||
else
|
||||
{
|
||||
stereo = new StereoGC(args[0]->IntegerValue(), args[1]->IntegerValue()); // max iterations
|
||||
}
|
||||
if (args.Length() == 0) {
|
||||
stereo = new StereoGC();
|
||||
} else if (args.Length() == 1) {
|
||||
// numberOfDisparities
|
||||
stereo = new StereoGC(args[0]->IntegerValue());
|
||||
} else {
|
||||
// max iterations
|
||||
stereo = new StereoGC(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
}
|
||||
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
stereo->Wrap(args.Holder());
|
||||
NanReturnValue(args.Holder());
|
||||
}
|
||||
|
||||
StereoGC::StereoGC(int numberOfDisparities, int maxIters)
|
||||
: ObjectWrap()
|
||||
{
|
||||
stereo = cvCreateStereoGCState(numberOfDisparities, maxIters);
|
||||
StereoGC::StereoGC(int numberOfDisparities, int maxIters) :
|
||||
ObjectWrap() {
|
||||
stereo = cvCreateStereoGCState(numberOfDisparities, maxIters);
|
||||
}
|
||||
|
||||
// TODO make this async
|
||||
NAN_METHOD(StereoGC::Compute)
|
||||
{
|
||||
SETUP_FUNCTION(StereoGC)
|
||||
NAN_METHOD(StereoGC::Compute) {
|
||||
SETUP_FUNCTION(StereoGC)
|
||||
|
||||
try {
|
||||
// Get the arguments
|
||||
try {
|
||||
// Get the arguments
|
||||
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
// Arg 0, the 'left' image
|
||||
Matrix* m0 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
cv::Mat left = m0->mat;
|
||||
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
// Arg 1, the 'right' image
|
||||
Matrix* m1 = ObjectWrap::Unwrap<Matrix>(args[1]->ToObject());
|
||||
cv::Mat right = m1->mat;
|
||||
|
||||
// Compute stereo using the block matching algorithm
|
||||
CvMat left_leg = left, right_leg = right;
|
||||
CvMat *disp_left = cvCreateMat(left.rows, left.cols, CV_16S), *disp_right = cvCreateMat(right.rows, right.cols, CV_16S);
|
||||
cvFindStereoCorrespondenceGC(&left_leg, &right_leg, disp_left, disp_right, self->stereo, 0);
|
||||
// Compute stereo using the block matching algorithm
|
||||
CvMat left_leg = left, right_leg = right;
|
||||
CvMat *disp_left = cvCreateMat(left.rows, left.cols, CV_16S), *disp_right =
|
||||
cvCreateMat(right.rows, right.cols, CV_16S);
|
||||
cvFindStereoCorrespondenceGC(&left_leg, &right_leg, disp_left, disp_right,
|
||||
self->stereo, 0);
|
||||
|
||||
cv::Mat disp16 = disp_left;
|
||||
cv::Mat disparity(disp16.rows, disp16.cols, CV_8U);
|
||||
disp16.convertTo(disparity, CV_8U, -16);
|
||||
cv::Mat disp16 = disp_left;
|
||||
cv::Mat disparity(disp16.rows, disp16.cols, CV_8U);
|
||||
disp16.convertTo(disparity, CV_8U, -16);
|
||||
|
||||
// Wrap the returned disparity map
|
||||
Local<Object> disparityWrap = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
// Wrap the returned disparity map
|
||||
Local < Object > disparityWrap =
|
||||
NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *disp = ObjectWrap::Unwrap<Matrix>(disparityWrap);
|
||||
disp->mat = disparity;
|
||||
|
||||
NanReturnValue(disparityWrap);
|
||||
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
};
|
||||
NanReturnValue(disparityWrap);
|
||||
} catch (cv::Exception &e) {
|
||||
const char *err_msg = e.what();
|
||||
NanThrowError(err_msg);
|
||||
NanReturnUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
53
src/Stereo.h
53
src/Stereo.h
@ -5,54 +5,49 @@
|
||||
|
||||
class StereoBM: public node::ObjectWrap {
|
||||
public:
|
||||
cv::StereoBM stereo;
|
||||
cv::StereoBM stereo;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
StereoBM(int preset = cv::StereoBM::BASIC_PRESET, int ndisparities = 0, int SADWindowSize=21);
|
||||
StereoBM(int preset = cv::StereoBM::BASIC_PRESET, int ndisparities = 0,
|
||||
int SADWindowSize = 21);
|
||||
|
||||
JSFUNC(Compute);
|
||||
JSFUNC(Compute)
|
||||
;
|
||||
};
|
||||
|
||||
class StereoSGBM: public node::ObjectWrap {
|
||||
public:
|
||||
cv::StereoSGBM stereo;
|
||||
cv::StereoSGBM stereo;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
StereoSGBM();
|
||||
StereoSGBM(int minDisparity,
|
||||
int ndisparities,
|
||||
int SADWindowSize,
|
||||
int p1 = 0,
|
||||
int p2 = 0,
|
||||
int disp12MaxDiff = 0,
|
||||
int preFilterCap = 0,
|
||||
int uniquenessRatio = 0,
|
||||
int speckleWindowSize = 0,
|
||||
int speckleRange = 0,
|
||||
bool fullDP = false);
|
||||
StereoSGBM();
|
||||
StereoSGBM(int minDisparity, int ndisparities, int SADWindowSize, int p1 = 0,
|
||||
int p2 = 0, int disp12MaxDiff = 0, int preFilterCap = 0,
|
||||
int uniquenessRatio = 0, int speckleWindowSize = 0, int speckleRange = 0,
|
||||
bool fullDP = false);
|
||||
|
||||
JSFUNC(Compute);
|
||||
JSFUNC(Compute);
|
||||
};
|
||||
|
||||
struct CvStereoGCState;
|
||||
|
||||
class StereoGC: public node::ObjectWrap {
|
||||
public:
|
||||
CvStereoGCState *stereo;
|
||||
CvStereoGCState *stereo;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
StereoGC(int numberOfDisparities = 16, int maxIterations = 2);
|
||||
StereoGC(int numberOfDisparities = 16, int maxIterations = 2);
|
||||
|
||||
JSFUNC(Compute);
|
||||
JSFUNC(Compute);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,155 +5,149 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
v8::Persistent<FunctionTemplate> VideoCaptureWrap::constructor;
|
||||
|
||||
struct videocapture_baton {
|
||||
|
||||
Persistent<Function> cb;
|
||||
VideoCaptureWrap *vc;
|
||||
Matrix *im;
|
||||
Persistent<Function> cb;
|
||||
VideoCaptureWrap *vc;
|
||||
Matrix *im;
|
||||
|
||||
uv_work_t request;
|
||||
uv_work_t request;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
VideoCaptureWrap::Init(Handle<Object> target) {
|
||||
void VideoCaptureWrap::Init(Handle<Object> target) {
|
||||
NanScope();
|
||||
|
||||
//Class
|
||||
//Class
|
||||
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(VideoCaptureWrap::New);
|
||||
NanAssignPersistent(constructor, ctor);
|
||||
ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
ctor->SetClassName(NanNew("VideoCapture"));
|
||||
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "read", Read);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setWidth", SetWidth);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setHeight", SetHeight);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setPosition", SetPosition);
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "read", Read);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setWidth", SetWidth);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setHeight", SetHeight);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setPosition", SetPosition);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "close", Close);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "ReadSync", ReadSync);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "grab", Grab);
|
||||
NODE_SET_PROTOTYPE_METHOD(ctor, "retrieve", Retrieve);
|
||||
|
||||
target->Set(NanNew("VideoCapture"), ctor->GetFunction());
|
||||
};
|
||||
target->Set(NanNew("VideoCapture"), ctor->GetFunction());
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::New) {
|
||||
NanScope();
|
||||
NanScope();
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
return NanThrowTypeError("Cannot Instantiate without new");
|
||||
return NanThrowTypeError("Cannot Instantiate without new");
|
||||
|
||||
VideoCaptureWrap *v;
|
||||
VideoCaptureWrap *v;
|
||||
|
||||
if (args[0]->IsNumber()){
|
||||
v = new VideoCaptureWrap(args[0]->NumberValue());
|
||||
} else {
|
||||
if (args[0]->IsNumber()) {
|
||||
v = new VideoCaptureWrap(args[0]->NumberValue());
|
||||
} else {
|
||||
//TODO - assumes that we have string, verify
|
||||
v = new VideoCaptureWrap(std::string(*NanAsciiString(args[0]->ToString())));
|
||||
}
|
||||
|
||||
v->Wrap(args.This());
|
||||
|
||||
v->Wrap(args.This());
|
||||
|
||||
NanReturnValue(args.This());
|
||||
NanReturnValue(args.This());
|
||||
}
|
||||
|
||||
VideoCaptureWrap::VideoCaptureWrap(int device){
|
||||
|
||||
NanScope();
|
||||
cap.open(device);
|
||||
|
||||
if(!cap.isOpened()){
|
||||
NanThrowError("Camera could not be opened");
|
||||
}
|
||||
}
|
||||
|
||||
VideoCaptureWrap::VideoCaptureWrap(const std::string& filename){
|
||||
VideoCaptureWrap::VideoCaptureWrap(int device) {
|
||||
NanScope();
|
||||
cap.open(filename);
|
||||
cap.open(device);
|
||||
|
||||
if(!cap.isOpened()) {
|
||||
NanThrowError("Camera could not be opened");
|
||||
}
|
||||
}
|
||||
|
||||
VideoCaptureWrap::VideoCaptureWrap(const std::string& filename) {
|
||||
NanScope();
|
||||
cap.open(filename);
|
||||
// TODO! At the moment this only takes a full path - do relative too.
|
||||
if(!cap.isOpened()){
|
||||
if(!cap.isOpened()) {
|
||||
NanThrowError("Video file could not be opened (opencv reqs. non relative paths)");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::SetWidth){
|
||||
NAN_METHOD(VideoCaptureWrap::SetWidth) {
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
int w = args[0]->IntegerValue();
|
||||
int w = args[0]->IntegerValue();
|
||||
|
||||
if(v->cap.isOpened())
|
||||
v->cap.set(CV_CAP_PROP_FRAME_WIDTH, w);
|
||||
if(v->cap.isOpened())
|
||||
v->cap.set(CV_CAP_PROP_FRAME_WIDTH, w);
|
||||
|
||||
NanReturnUndefined();
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::SetHeight){
|
||||
NAN_METHOD(VideoCaptureWrap::SetHeight) {
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
int h = args[0]->IntegerValue();
|
||||
int h = args[0]->IntegerValue();
|
||||
|
||||
v->cap.set(CV_CAP_PROP_FRAME_HEIGHT, h);
|
||||
v->cap.set(CV_CAP_PROP_FRAME_HEIGHT, h);
|
||||
|
||||
NanReturnUndefined();
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::SetPosition){
|
||||
NAN_METHOD(VideoCaptureWrap::SetPosition) {
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
if(args.Length() != 1)
|
||||
NanReturnUndefined();
|
||||
|
||||
int pos = args[0]->IntegerValue();
|
||||
int pos = args[0]->IntegerValue();
|
||||
|
||||
v->cap.set(CV_CAP_PROP_POS_FRAMES, pos);
|
||||
v->cap.set(CV_CAP_PROP_POS_FRAMES, pos);
|
||||
|
||||
NanReturnUndefined();
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Close){
|
||||
NAN_METHOD(VideoCaptureWrap::Close) {
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
v->cap.release();
|
||||
|
||||
v->cap.release();
|
||||
|
||||
NanReturnUndefined();
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
|
||||
class AsyncVCWorker : public NanAsyncWorker {
|
||||
public:
|
||||
class AsyncVCWorker: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncVCWorker(NanCallback *callback, VideoCaptureWrap* vc,
|
||||
bool retrieve = false, int channel = 0)
|
||||
: NanAsyncWorker(callback), vc(vc),
|
||||
retrieve(retrieve), channel(channel) {}
|
||||
~AsyncVCWorker() {}
|
||||
bool retrieve = false, int channel = 0) :
|
||||
NanAsyncWorker(callback),
|
||||
vc(vc),
|
||||
retrieve(retrieve),
|
||||
channel(channel) {
|
||||
}
|
||||
|
||||
~AsyncVCWorker() {
|
||||
}
|
||||
|
||||
// Executed inside the worker-thread.
|
||||
// It is not safe to access V8, or V8 data structures
|
||||
// here, so everything we need for input and output
|
||||
// should go on `this`.
|
||||
void Execute () {
|
||||
void Execute() {
|
||||
if (retrieve) {
|
||||
if (!this->vc->cap.retrieve(mat, channel)) {
|
||||
SetErrorMessage("retrieve failed");
|
||||
@ -166,18 +160,18 @@ class AsyncVCWorker : public NanAsyncWorker {
|
||||
// Executed when the async work is complete
|
||||
// this function will be run inside the main event loop
|
||||
// so it is safe to use V8 again
|
||||
void HandleOKCallback () {
|
||||
void HandleOKCallback() {
|
||||
NanScope();
|
||||
|
||||
|
||||
Local<Object> im_to_return= NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
img->mat = mat;
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
img->mat = mat;
|
||||
|
||||
Local<Value> argv[] = {
|
||||
NanNull()
|
||||
NanNull()
|
||||
, im_to_return
|
||||
};
|
||||
|
||||
|
||||
TryCatch try_catch;
|
||||
callback->Call(2, argv);
|
||||
if (try_catch.HasCaught()) {
|
||||
@ -185,61 +179,58 @@ class AsyncVCWorker : public NanAsyncWorker {
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
VideoCaptureWrap *vc;
|
||||
cv::Mat mat;
|
||||
bool retrieve;
|
||||
int channel;
|
||||
};
|
||||
|
||||
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Read) {
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
REQ_FUN_ARG(0, cb);
|
||||
REQ_FUN_ARG(0, cb);
|
||||
|
||||
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||
NanAsyncQueueWorker(new AsyncVCWorker(callback, v));
|
||||
|
||||
NanReturnUndefined();
|
||||
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::ReadSync) {
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
Local<Object> im_to_return= NanNew(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
|
||||
v->cap.read(img->mat);
|
||||
|
||||
NanReturnValue(im_to_return);
|
||||
NanReturnValue(im_to_return);
|
||||
}
|
||||
|
||||
class AsyncGrabWorker: public NanAsyncWorker {
|
||||
public:
|
||||
AsyncGrabWorker(NanCallback *callback, VideoCaptureWrap* vc) :
|
||||
NanAsyncWorker(callback),
|
||||
vc(vc) {
|
||||
}
|
||||
|
||||
class AsyncGrabWorker : public NanAsyncWorker {
|
||||
public:
|
||||
AsyncGrabWorker(NanCallback *callback, VideoCaptureWrap* vc)
|
||||
: NanAsyncWorker(callback), vc(vc) {}
|
||||
~AsyncGrabWorker() {}
|
||||
~AsyncGrabWorker() {
|
||||
}
|
||||
|
||||
void Execute () {
|
||||
void Execute() {
|
||||
if (!this->vc->cap.grab()) {
|
||||
SetErrorMessage("grab failed");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
VideoCaptureWrap *vc;
|
||||
};
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Grab) {
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
@ -252,7 +243,6 @@ NAN_METHOD(VideoCaptureWrap::Grab) {
|
||||
}
|
||||
|
||||
NAN_METHOD(VideoCaptureWrap::Retrieve) {
|
||||
|
||||
NanScope();
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
@ -265,4 +255,3 @@ NAN_METHOD(VideoCaptureWrap::Retrieve) {
|
||||
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
||||
|
||||
@ -1,32 +1,32 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
class VideoCaptureWrap: public node::ObjectWrap {
|
||||
public:
|
||||
cv::VideoCapture cap;
|
||||
public:
|
||||
cv::VideoCapture cap;
|
||||
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
VideoCaptureWrap(const std::string& filename);
|
||||
VideoCaptureWrap(int device);
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static NAN_METHOD(New);
|
||||
|
||||
static NAN_METHOD(Read);
|
||||
static NAN_METHOD(ReadSync);
|
||||
VideoCaptureWrap(const std::string& filename);
|
||||
VideoCaptureWrap(int device);
|
||||
|
||||
static NAN_METHOD(Grab);
|
||||
static NAN_METHOD(Retrieve);
|
||||
static NAN_METHOD(Read);
|
||||
static NAN_METHOD(ReadSync);
|
||||
|
||||
//(Optional) For setting width and height of the input video stream
|
||||
static NAN_METHOD(SetWidth);
|
||||
static NAN_METHOD(SetHeight);
|
||||
|
||||
// to set frame position
|
||||
static NAN_METHOD(SetPosition);
|
||||
static NAN_METHOD(Grab);
|
||||
static NAN_METHOD(Retrieve);
|
||||
|
||||
static NAN_METHOD(GetFrameAt);
|
||||
// (Optional) For setting width and height of the input video stream
|
||||
static NAN_METHOD(SetWidth);
|
||||
static NAN_METHOD(SetHeight);
|
||||
|
||||
//close the stream
|
||||
static NAN_METHOD(Close);
|
||||
// to set frame position
|
||||
static NAN_METHOD(SetPosition);
|
||||
|
||||
static NAN_METHOD(GetFrameAt);
|
||||
|
||||
//close the stream
|
||||
static NAN_METHOD(Close);
|
||||
};
|
||||
|
||||
|
||||
44
src/init.cc
44
src/init.cc
@ -15,31 +15,29 @@
|
||||
#include "Stereo.h"
|
||||
#include "BackgroundSubtractor.h"
|
||||
|
||||
extern "C" void
|
||||
init(Handle<Object> target) {
|
||||
NanScope();
|
||||
OpenCV::Init(target);
|
||||
extern "C" void init(Handle<Object> target) {
|
||||
NanScope();
|
||||
OpenCV::Init(target);
|
||||
|
||||
Point::Init(target);
|
||||
Matrix::Init(target);
|
||||
CascadeClassifierWrap::Init(target);
|
||||
VideoCaptureWrap::Init(target);
|
||||
Contour::Init(target);
|
||||
TrackedObject::Init(target);
|
||||
NamedWindow::Init(target);
|
||||
Constants::Init(target);
|
||||
Calib3D::Init(target);
|
||||
ImgProc::Init(target);
|
||||
StereoBM::Init(target);
|
||||
StereoSGBM::Init(target);
|
||||
StereoGC::Init(target);
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
BackgroundSubtractorWrap::Init(target);
|
||||
Features::Init(target);
|
||||
FaceRecognizerWrap::Init(target);
|
||||
#endif
|
||||
Point::Init(target);
|
||||
Matrix::Init(target);
|
||||
CascadeClassifierWrap::Init(target);
|
||||
VideoCaptureWrap::Init(target);
|
||||
Contour::Init(target);
|
||||
TrackedObject::Init(target);
|
||||
NamedWindow::Init(target);
|
||||
Constants::Init(target);
|
||||
Calib3D::Init(target);
|
||||
ImgProc::Init(target);
|
||||
StereoBM::Init(target);
|
||||
StereoSGBM::Init(target);
|
||||
StereoGC::Init(target);
|
||||
|
||||
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||
BackgroundSubtractorWrap::Init(target);
|
||||
Features::Init(target);
|
||||
FaceRecognizerWrap::Init(target);
|
||||
#endif
|
||||
};
|
||||
|
||||
NODE_MODULE(opencv, init)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user