OpenCV imwrite is not working

后端 未结 3 1911
名媛妹妹
名媛妹妹 2021-01-25 04:17

I have a simple OpenCV application that takes a video stream from the webcam, and when the spacebar is pressed it captures the current image and freezes on that ima

相关标签:
3条回答
  • 2021-01-25 04:55

    You are attempting to write testimage.jpg to the / directory. The executing program probably doesn't have sufficient permissions to write to that directory. Based on your comment, you probably want

    //trying to save to current directory
    bool maybe = imwrite("./testimage.jpg", picture);
    

    Since . denotes the current working directory.

    0 讨论(0)
  • 2021-01-25 05:01

    OpenCV sometimes has problems to write to a .jpg image. Try to change that to .png or .bmp to see if that makes a difference in your case.

    If you have further issues with writing images, you can debug them in OpenCV by adding this few lines of code to display them and see if they are valid:

    // Create a window for display.
    namedWindow( "Display window", WINDOW_AUTOSIZE );
    
    // Show our image inside it.
    imshow( "Display window", picture );                   
    
    // Wait for a keystroke in the window
    waitKey(0);                                         
    
    0 讨论(0)
  • 2021-01-25 05:02

    A few suggestions.

    1. try a different file format.
    2. does your IDE defiantly know your target folder / home path directory?
    3. Is your image definitely valid? does it show when you imshow()?
    0 讨论(0)
提交回复
热议问题