Cv.SaveImage in openCV

I am trying to learn how to use opencv in python and have some difficulties, and I am also new to python too.

Here is my question:

I want to convert jpg tp png file. Simple and straightforward. But when I run this code:

from opencv import _cv

from opencv.highgui import cvSaveImage, cvLoadImage


cvSaveImage("bet.jpg",cvLoadImage("bet.jpg")) 



if __name__ == '__main__':
    pass

It gives this error, which I do not understand:

Traceback (most recent call last):
  File "convert.py", line 6, in <module>
    cvSaveImage("bet.jpg",cvLoadImage("bet.jpg")) 
  File "/usr/lib/pymodules/python2.6/opencv/highgui.py", line 183, in cvSaveImage
    return _highgui.cvSaveImage(*args)
RuntimeError:  openCV Error:
        Status=Null pointer
        function name=cvGetMat
        error message=NULL array pointer is passed
        file_name=cxarray.cpp
        line=2780

I have an image with the same source folder, and the image name is bet.jpg

Any idea ??

+3
source share
3 answers

I solved the problem, the image that I accidentally selected from Google Images is not loading. Maybe it is encrypted or something I do not know. I tried this with other images, and worked very well. So watch out for image copying :)

+1
source

The best choice is pyopencv:

import pyopencv as cv

img = cv.imread('01.png')

cv.imshow('img-windows',img)
cv.waitKey(0)
cv.imwrite('01.png',img)
+9

Python CV, CV2 jpeg png:   Python: cv2.imwrite(filename, img[, params]) → retval

: `

import cv2
filename = 'pic.jpeg'
cam = cv2.VideoCapture(filename)
s, img = cam.read()
picName = 'pic.png'
cv2.imwrite(picName, img)`

VideoCapture is good and generic, and works with video, webcams, and image files.

+4
source

Source: https://habr.com/ru/post/1737338/


All Articles