import cv2 as cv
import sys
img = cv.imread(cv.samples.findFile("starry_night.jpg"))
if img is None:
sys.exit("Could not read the image.")
cv.imshow("Display window", img)
k = cv.waitKey(0)
if k == ord("s"):
cv.imwrite("starry_night.png", img)
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
int main()
{
std::string image_path = samples::findFile("starry_night.jpg");
Mat img = imread(image_path, IMREAD_COLOR);
if(img.empty())
{
std::cout << "Could not read the image: " << image_path << std::endl;
return 1;
}
imshow("Display window", img);
int k = waitKey(0); // Wait for a keystroke in the window
if(k == 's')
{
imwrite("starry_night.png", img);
}
return 0;
}
Create a CMake file, known as CMakeLists.txt
https://docs.opencv.org/4.6.0/db/df5/tutorial_linux_gcc_cmake.html
cmake_minimum_required(VERSION 2.8)
project(DisplayImage)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(DisplayImage DisplayImage.cpp)
target_link_libraries(DisplayImage ${OpenCV_LIBS})
Build the executable file
https://docs.opencv.org/4.6.0/db/df5/tutorial_linux_gcc_cmake.html
cd <DisplayImage_directory>
cmake .
make
Display the image
Learn More →
Key 's' to save it
Learn More →
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the original frame
cv.imshow('color frame', frame)
# Display the resulting frame
cv.imshow('gray frame', gray)
if cv.waitKey(1) == ord('q'):
break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
#include <iostream> // for standard I/O
#include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat)
#include <opencv2/videoio.hpp> // Video I/O
#include <opencv2/highgui.hpp> // for gui applications, like imshow()
#include <opencv2/gapi/core.hpp> // for image processing
using namespace std;
using namespace cv;
int main()
{
VideoCapture cap_vid;
int cam_id = 0; // Camera ID
cap_vid.open(cam_id); // Open video
if (!cap_vid.isOpened())
{
cout << "Could not open the camera, id: " << cam_id << endl;
return -1;
}
Mat frame;
Mat gray;
do
{
// Capture frames
bool ret = cap_vid.read(frame);
if (!ret) {
cout << "Can't receive frame (stream end?). Exiting ...\n";
break;
}
// Color to gray
cvtColor(frame, gray, COLOR_BGR2GRAY);
// Display live frames
imshow("Live", frame); // Color
// imshow("live", gray); // Gray
} while (waitKey(30) != 'q');
return 0;
}
cmake_minimum_required(VERSION 2.8)
project(CaptureVideo)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(CaptureVideo CaptureVideo.cpp)
target_link_libraries(CaptureVideo ${OpenCV_LIBS})
$ cd <CaptureVideo_directory> && mkdir build
$ cd build # Collect all of the files generated by cmake.
$ cmake ../
$ make
View the slide with "Slide Mode".
Jul 20, 2022Qt Creator Installation on Ubuntu 18.04 The following scripts can be written to a bash file named "qtcreator_install.sh". YELLOW="\e[1;33m" ENDCOLOR="\e[m" echo -e "${YELLOW}[Begin to install Qt Creator 4.5.2 & Qt 5.9.5]${ENDCOLOR}" echo -e "${YELLOW}[Update the package lists]${ENDCOLOR}"
Jul 19, 2022VS Code Installation on Ubuntu 18.04 The following scripts can be written to a bash file named "vscode_install.sh". YELLOW="\e[1;33m" ENDCOLOR="\e[m" echo -e "${YELLOW}[Begin to install VS CODE]${ENDCOLOR}" echo -e "${YELLOW}[Add key and source list of vscode to apt]${ENDCOLOR}"
Jul 19, 2022Item Detail Remark 格式 首要任務:下載研討會或期刊規定格式。 雖說萬事起頭難,但這步驟一點都不難,就跟使用計算機前先按下開關一樣簡單。 流水號 章節、圖、表、方程式、參考文獻 。
Jun 28, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up