cmake_minimum_required (VERSION 3.8)
project ("CMakeProject1")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "D:\\Project\\video-matting\\libtorch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
find_package(Torch REQUIRED)
include_directories("D:/Program Files/opencv/build/include")
include_directories("D:/Program Files/opencv/build/include/opencv2")
link_directories("D:/Program Files/opencv/build/x64/vc15/lib")
add_executable (CMakeProject1 "CMakeProject1.cpp" "CMakeProject1.h")
target_link_libraries(CMakeProject1 "${TORCH_LIBRARIES}")
target_link_libraries(CMakeProject1 opencv_world455d)
set_property(TARGET CMakeProject1 PROPERTY CXX_STANDARD 14)
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET CMakeProject1
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:CMakeProject1>)
endif (MSVC)
#pragma once
#include <torch/script.h>
#include <torch/torch.h>
#include <fstream>
#include <iostream>
#include <memory>
#include <opencv2/opencv.hpp>
int main() {
cv::imshow("hello", cv::imread("C:\\Users\\bernard\\Pictures\\深目迅影.png"));
cv::waitKey(0);
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
return 0;
}