pupil-labs / libuvc

a cross-platform library for USB video devices
https://int80k.com/libuvc/
Other
52 stars 30 forks source link

Sample code not giving any output neither any error #46

Open lafith opened 2 years ago

lafith commented 2 years ago

Hi, I built libuvc in windows without any error following your instructions. I wrote few lines just to check if it is working. It is running without any error but it is also not printing out anything.

Screenshot (33)

main.cpp

#include <iostream>
#include <libuvc/libuvc.h>

int main(){
  std::cout<<"UVC Test:"<<std::endl;
  uvc_context_t *ctx = nullptr;
  uvc_error_t res = uvc_init(&ctx, nullptr);
  if (res < 0)
    {
        uvc_perror(res, "uvc_init error");
        std::cout<<"error"<<std::endl;
    }
    uvc_exit(ctx);
    std::cout<<"Done!"<<std::endl;
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(WebCam_MicrosoftMediaFoundation VERSION 0.1.0)

include_directories(include)
file(GLOB SOURCES "src/*.cpp")

find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )

set(libuvc_DIR C:/libuvc/build/CMakeFiles)
find_package(libuvc REQUIRED)
include_directories( C:/libuvc/include )

include(CTest)
enable_testing()

add_executable(OpenCV_Test
                ${SOURCES})

target_link_libraries( OpenCV_Test ${OpenCV_LIBS} C:/libuvc/build/Release/uvc.lib)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
papr commented 2 years ago

Hi, Unfortunately, I do not have an idea what could be going wrong in your example. I would recommend starting with the simplest possible example (just printing something) and then adding complexity step by step to find the step causing the program to stop working.

lafith commented 2 years ago

Ok I tried this approach and this is when I am getting no output nor error. Do you have any idea where could be the problem?

#include <iostream>
#include <libuvc/libuvc.h>

int main(){
  std::cout<<"UVC Test:"<<std::endl;
  uvc_context_t *ctx = nullptr;
  uvc_error_t res = uvc_init(&ctx, nullptr);
//  if (res < 0)
//    {
//        uvc_perror(res, "uvc_init error");
//        std::cout<<"error"<<std::endl;
//    }
//    uvc_exit(ctx);
//   std::cout<<"Done!"<<std::endl;
     return 0;
}
papr commented 2 years ago

@lafith uvc_init compares against NULL, not nullptr. I do not know enough about c++ to know if this makes a difference. Please give passing NULL instead a try.

lafith commented 2 years ago

@papr No, same result :(