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 "text_types.hh"
#include <fstream>
#include <iostream>
// Only for build in this repository
#define text_globs supported_globs
@ -215,12 +216,15 @@ void TextEditor::search_entry_changed()
Gtk::TextIter start, end;
// 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;
curr_iter_down = end;
buffer1->select_range(start, end);
textview1.scroll_to(start);
if (buffer1->begin().forward_search(text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end))
{
curr_iter_up = 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;
// 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;
curr_iter_down = end;
buffer1->select_range(start, end);
textview1.scroll_to(start);
if (curr_iter_down.forward_search(search_text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end))
{
curr_iter_up = 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;
// 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;
curr_iter_down = end;
buffer1->select_range(start, end);
textview1.scroll_to(start);
if (curr_iter_up.backward_search(search_text, Gtk::TEXT_SEARCH_CASE_INSENSITIVE, start, end))
{
curr_iter_up = 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();
}
void TextEditor::about_activated(){
void TextEditor::about_activated()
{
char *version, *copyright;
// The Gtkmm Version
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,
"logo-icon-name", "org.gtk.daleclack",
"title", "About Simple text editor",
NULL);
(char *)NULL);
// Free memory
g_free(version);
g_free(copyright);

View File

@ -4,33 +4,17 @@
using namespace cv;
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;
std::cout << "Save gray and hsv images? (Y/N)";
std::cin >> save_images;
// Open the image
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);
// Create windows
namedWindow("image1", WINDOW_AUTOSIZE);
namedWindow("image2", WINDOW_AUTOSIZE);
imshow("image1", image);
imshow("image2", image2);
waitKey(0);
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;
}