I have the following code. I had made a GUI interface and i wan't to store the images in a folder that the program will be created.
TypeError: coercing to Unicode: need string or buffer, list found
I also tried to make String from Qstring,but didn't worked..or maybe,i don't know how to save the images. Any ideas?
If face_img
is a list you will have to convert all elements separately:
face_img = [unicode(elem, encoding="UTF-8") for elem in face_img]
Or, convert only the first element when you use it:
cv2.imwrite(folder + '/' + str(counter) + '.jpg', unicode(face_img[0], encoding="UTF-8"))
However, typically you don't need to convert from QString
to str
yourself. Usually PyQt
does the conversion automatically. The fact that you encounter a QString
is strange. This is the underlying issue that needs to be investigated IHMO, the fixes above are just hacks around the actual problem.
I suspect that somewhere in the operatii
module a QString
is created explicitly. However, I cannot check this because I don't have the operatii
module. You code example is not complete . Please read this post on how to make a Minimal, Complete and Verifiable example . By posting an MCVE you will get you a lot more help in the future.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.