cmake libtorch opencv vs cmakelists

cmake libtorch opencv vs cmakelists,第1张

# CMakeList.txt: CMakeProject1 的 CMake 项目,在此处包括源代码并定义
# 项目特定的逻辑。
#
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)

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
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 
#include 
#include 
#include 
#include 
#include 
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;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/739768.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存