opencv fisherface recognizer - python-3.x

I'm trying to load model files for a FisherFaceRecognizer. The initial problem is that the program was written for an older OpenCV version and it seems some interfaces were changed.
Info about my project:
programming language: Python 3.5
OpenCV Version: 3.3.0
These are the two lines were I had a problem with:
model = cv2.face.createFisherFaceRecognizer()
model.load('foo_model.xml')
In the OpenCV documentation I found out that there is a new way to call the create functions and it seems to work. But I could not find the right call for the load function. I have tried to use the read function of the recognizer, but that results in an error.
model = cv2.face.FisherFaceRecognizer_create()
model.read('foo_model.xml')
The error message I've got when I try to use read():
File can't be opened for reading! in function read
Does somebody can help me with loading the model files? Thank you :)

The problem is with the xml file format. if you open the XML file you will not find "my_object" tag. I will not go to the details of this but, every time I face this problem, it works when I modify the xml file as follows.
<?xml version="1.0"?>
<opencv_storage>
<my_object> //add this
.........
.........
.........
</my_object> //and this
</opencv_storage>

The problem seems to be that the xml format in which the models are saved had been changed. This seems to be a known issue. I am using OpenCV 3.3.0 and want to load a model from an older OpenCV version which results in the mentioned error from the read-function. In the OpenCV Q&A forum a solution was suggested to me, but in my case it did not work. Nonetheless I will drop the link to my post at OpenCV Q&A here. Maybe someone else with the same problem can benefit from it.

Related

PySide6: fail to load "jpg" format in QPixmap

I'm trying to load "jpg" picture on the QLabel in PySide6. So I used this:
mypic = QPixmap()
mypic.load("./test.jpg")
self.ui.mylabel.setPixmap(QPixmap(mypic))
However, I found there is empty in mylabel. When I debug in this program, I found that my pic is null (even after it loads the image file).
So I wonder if the jpg is not automatically supported in PySide6.
As I checked the documention of PySide6, it illustrates that the default supporting image formats include "jpg".
enter image description here
As I print the supportedImageFormats using:
print(QtGui.QImageReader.supportedImageFormats())
It returns with this:
[PySide6.QtCore.QByteArray(b'bmp'), PySide6.QtCore.QByteArray(b'pbm'), PySide6.QtCore.QByteArray(b'pgm'), PySide6.QtCore.QByteArray(b'png'), PySide6.QtCore.QByteArray(b'ppm'), PySide6.QtCore.QByteArray(b'xbm'), PySide6.QtCore.QByteArray(b'xpm')]
I found it does not include the "jpg" format by default!
Then I searched a lot of solutions, I found that this can solve my problem: add one line of code to introduce the "imageformats" plugins in PySide6 folder.
app.addLibraryPath(os.path.join(os.path.dirname(QtCore.__file__), "plugins"))
Here I printed the os.path.dirname(QtCore.__file__), and found it was my PySide6 folder.
I checked the plugins folder, and found the inner imageformats folder, and found these dlls:
enter image description here
It seems that the jpg format is supported here. So when I add the plugin path, it can solve my problem. But it still confuses me that why I should add the plugin path (The official documentation implies that this format is supported by default!).
I wonder if there is a more convincing solution because adding one line of code in my program every time seems clumsy. Or if I left out something. I sincerely want to get your help. Thank you!

How to add Metadata in the Tensorflow Lite for a model taken from Github?

I have used this project from Github: https://github.com/nicknochnack/TFODCourse
The project contains a model that can detect License Plate on a given Vehicle image. The Github repo also contains code for the conversion of model into Tensorflow Lite file.
I used that code to generate TFLite file.
And then, I followed this link: https://developers.google.com/codelabs/tflite-object-detection-android
Where I downloaded the sample Application of Object detection model and following the instructions, I copied my TFLite files into the Android Application.
Now, if I run the application and take a photo, it gives me this error,
/TaskJniUtils: Error getting native address of native library: task_vision_jni
java.lang.RuntimeException: Error occurred when initializing ObjectDetector: Input tensor has type kTfLiteFloat32: it requires specifying NormalizationOptions metadata to preprocess input images.
at org.tensorflow.lite.task.vision.detector.ObjectDetector
I understand that I have to add Metadata in my TFLite model. so, I searched about it and ended up on this link: https://www.tensorflow.org/lite/models/convert/metadata#model_with_metadata_format
But I didn't understand at all what exactly should I be doing. Can anyone please help me in pointing to the right direction that for my problem specifically, what exactly do I need to do?

Unable to solve multiprocessing.Manager.Lock() error in Python code (VS editor)

I am using machine learning in my Python (version 3.8.5) code. In the preprocessing part, I need to hash encode few features. So earlier I have dumped a hash encoder pickle file using the features in the training phase. Saved the file with the name of 'hash_encoder.pkl'. Now in the testing phase, I need to transform the features using this pickle file. I'm using the following code given in screenshot to hash encode three string features as given in the first line.
In the encoder.transform line, I'm getting the error of "data_lock=mutiprocessing.Manager().Lock()".
At the end I'm also getting 'raise EOF error'.
I have tried using same version of pandas (1.1.3) to dump the hash_encoder file and also to load it. I'm not sure why is this coming up.
Can someone help me in understand or debugging this part?
I have added the screenshot of the error.

CSV Input in gensim LDA via corpora.csvcorpus

I wanna use the LDA in gensim for topic modeling over a few thousand documents.
Therefore I´m using a csv-File as Input in the format of a term-document-matrix.
Currently it occurs an error when running the following code:
from gensim import corpora
import_path ="TDM.csv"
dictionary = corpora.csvcorpus(import_path, labels='true')
The error is the following:
dictionary = corpora.csvcorpus(import_path, labels='true')
AttributeError: module 'gensim.corpora' has no attribute 'csvcorpus'
Am I using the module correctly and if so, where is my mistake?
Thanks in advance.
This also bugged me for quite awhile.
It looks like csvcorpus is actually in the experimental stage as you can see in their github issue, https://github.com/RaRe-Technologies/gensim/issues/1583
I would recommend going by the old fashioned way of using the csv package to read your csv file instead.
Cheers.

How to import an existing PDF file in node.js

I am working on import routines for node, so far I can import text nodes from a PDF using pdf2json, this works well, but doesn't work on PDF's that are image based and contain no text.
So I downloaded pdf2img, however there are plenty of issues with this module, the one I have now is that after running it, I get a lot of 0 byte png files created, no content and an error message:
/docfire/node_modules/gm/lib/command.js:228
proc.stdin.once('error', cb);
^
TypeError: Cannot read property 'once' of undefined
at gm._spawn (/docfire/node_modules/gm/lib/command.js:228:15)
at /docfire/node_modules/gm/lib/command.js:140:19
at series (/docfire/node_modules/array-series/index.js:11:36)
at gm._preprocess
(/docfire/node_modules/gm/lib/command.js:177:5)
at gm.stream (/docfire/node_modules/gm/lib/command.js:138:10)
at convertPdf2Img (/docfire/node_modules/pdf2img/lib/pdf2img.js:93:6)
at /docfire/node_modules/pdf2img/lib/pdf2img.js:67:9
at /docfire/node_modules/async/lib/async.js:246:17
at /docfire/node_modules/async/lib/async.js:122:13
at _each (/docfire/node_modules/async/lib/async.js:46:13)
I've tried posting a issue on the GIT site for the module, but it looks like quite a few people are having exactly the same problem and there doesn't seem to be any activity regarding any fixes.
What I would ideally like is a way to extract text and images from a PDF for node.
I'm running on an iMAC running macOS Sierra v10.12.4
With node version 7.8.0, pdf2img 0.2.0, gm 1.23.0
You can try pdf-image npm package.
https://www.npmjs.com/package/pdf-image
Hope this helps.

Resources