Add OpenCV test3 and test4

This commit is contained in:
daleclack 2022-07-16 12:32:33 +08:00
parent f8516efeab
commit 52d4c85dc9
5 changed files with 100 additions and 43 deletions

View File

@ -1,6 +1,7 @@
#include "TextEditor.hh" #include "TextEditor.hh"
#include "text_types.hh" #include "text_types.hh"
#include <fstream> #include <fstream>
#include <iostream>
// Only for build in this repository // Only for build in this repository
#define text_globs supported_globs #define text_globs supported_globs
@ -215,12 +216,15 @@ void TextEditor::search_entry_changed()
Gtk::TextIter start, end; Gtk::TextIter start, end;
// If get text to search, select the text and storage the position // If get text to search, select the text and storage the position
if (buffer1->begin().forward_search(text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end)) if (text.length() != 0)
{ {
curr_iter_up = start; if (buffer1->begin().forward_search(text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end))
curr_iter_down = end; {
buffer1->select_range(start, end); curr_iter_up = start;
textview1.scroll_to(start); curr_iter_down = end;
buffer1->select_range(start, end);
textview1.scroll_to(start);
}
} }
} }
@ -231,12 +235,15 @@ void TextEditor::search_forward()
Gtk::TextIter start, end; Gtk::TextIter start, end;
// Get Text to search, down to the end of text // Get Text to search, down to the end of text
if (curr_iter_down.forward_search(search_text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end)) if (search_text.length() != 0)
{ {
curr_iter_up = start; if (curr_iter_down.forward_search(search_text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end))
curr_iter_down = end; {
buffer1->select_range(start, end); curr_iter_up = start;
textview1.scroll_to(start); curr_iter_down = end;
buffer1->select_range(start, end);
textview1.scroll_to(start);
}
} }
} }
@ -247,12 +254,15 @@ void TextEditor::search_backward()
Gtk::TextIter start, end; Gtk::TextIter start, end;
// Get Text to search // Get Text to search
if (curr_iter_up.backward_search(search_text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end)) if (search_text.length() != 0)
{ {
curr_iter_up = start; if (curr_iter_up.backward_search(search_text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end))
curr_iter_down = end; {
buffer1->select_range(start, end); curr_iter_up = start;
textview1.scroll_to(start); curr_iter_down = end;
buffer1->select_range(start, end);
textview1.scroll_to(start);
}
} }
} }
@ -313,7 +323,8 @@ void TextEditor::infobar_response(int response)
infobar.hide(); infobar.hide();
} }
void TextEditor::about_activated(){ void TextEditor::about_activated()
{
char *version, *copyright; char *version, *copyright;
// The Gtkmm Version // The Gtkmm Version
version = g_strdup_printf("1.0\nRunning Against Gtkmm %d.%d.%d", version = g_strdup_printf("1.0\nRunning Against Gtkmm %d.%d.%d",
@ -333,7 +344,7 @@ void TextEditor::about_activated(){
"license-type", GTK_LICENSE_GPL_3_0, "license-type", GTK_LICENSE_GPL_3_0,
"logo-icon-name", "org.gtk.daleclack", "logo-icon-name", "org.gtk.daleclack",
"title", "About Simple text editor", "title", "About Simple text editor",
NULL); (char *)NULL);
// Free memory // Free memory
g_free(version); g_free(version);
g_free(copyright); g_free(copyright);

View File

@ -4,33 +4,17 @@
using namespace cv; using namespace cv;
int main(int argc, char ** argv){ int main(int argc, char ** argv){
std::string filename, save_images; // Create image objects
Mat image = Mat::zeros(Size(400,400), CV_8UC3);
image = Scalar(255, 0, 0);
Mat image2 = image.clone();
image2 = Scalar(0, 225, 0);
std::cin >> filename; // Create windows
std::cout << "Save gray and hsv images? (Y/N)"; namedWindow("image1", WINDOW_AUTOSIZE);
std::cin >> save_images; namedWindow("image2", WINDOW_AUTOSIZE);
imshow("image1", image);
// Open the image imshow("image2", image2);
Mat image, image_hsv, image_gray;
image = imread(filename, IMREAD_COLOR);
if(image.empty()){
std::cout << "failed to open the image";
return -1;
}
cvtColor(image, image_hsv, COLOR_BGR2HSV);
cvtColor(image, image_gray, COLOR_BGR2GRAY);
// Show the converted images
namedWindow("Original Image", WINDOW_FREERATIO);
imshow("Original Image", image);
namedWindow("HSV Image", WINDOW_FREERATIO);
imshow("HSV Image", image_hsv);
namedWindow("Gray Image", WINDOW_FREERATIO);
imshow("Gray Image", image_gray);
// Write the images
imwrite("image_gray.png", image_gray);
imwrite("image_hsv.png", image_hsv);
waitKey(0); waitKey(0);
destroyAllWindows(); destroyAllWindows();

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0.0)
project(OpenCV_test3 VERSION 1.0.0)
#Find the opencv package
find_package(OpenCV REQUIRED)
#include directories for opencv
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
#Add command to generate .gitignore
add_custom_command(TARGET ${PROJECT_NAME}
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
#Add OpenCV Libraries
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

View File

@ -0,0 +1,41 @@
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char **argv)
{
// Create capture object to capture video
VideoCapture capture(0);
if (!capture.isOpened())
{
std::cout << "Can't open video device!" << std::endl;
return -1;
}
// properties
double rate = capture.get(CAP_PROP_FPS);
double width = capture.get(CAP_PROP_FRAME_WIDTH);
double height = capture.get(CAP_PROP_FRAME_HEIGHT);
// Information about the camera
std::cout << "Frame Rate = " << rate << "width = " << width << "height = " << height << std::endl;
namedWindow("Video Capture", WINDOW_NORMAL);
Mat frame;
while (1)
{
if (!capture.read(frame))
{
std::cout << "no video frame" << std::endl;
continue;
}
imshow("Video Capture", frame);
waitKey(1);
}
capture.release();
return 0;
}