using System; using System.IO; using System.Text; class Program { static void Main(string[] args) { string filePath = "yourfile.txt"; byte[] fileBytes = File.ReadAllBytes(filePath); bool isUtf8 = IsValidUtf8(fileBytes); bool isShiftJis = IsValidShiftJis(fileBytes); if (isUtf8) { Console.WriteLine("The file is likely UTF-8 encoded."); } else if (isShiftJis) { Console.WriteLine("The file is likely Shift JIS encoded."); } else { Console.WriteLine("Encoding could not be determined."); } } static bool IsValidUtf8(byte[] bytes) { try { Encoding utf8 = new UTF8Encoding(false, true); utf8.GetString(bytes); return true; } catch { return false; } } static bool IsValidShiftJis(byte[] bytes) { try { Encoding shiftJis = Encoding.GetEncoding("shift_jis", new EncoderExceptionFallback(), new DecoderExceptionFallback()); shiftJis.GetString(bytes); return true; } catch { return false; } } }That's all :)
Everything void
Everything is void, but it's too real and too good to say so ;)
Sunday, September 15, 2024
How to detect if a text file is using Shift JIS encoding or UTF8 encoding using C#
Below is the sample source code generated by ChatGPT (GPT-4o) when I asked the question on how to detect encoding of Shift JIS and UTF8 using C#.
Labels:
C#
Thursday, November 23, 2017
cordova run android Error: spawn EACCES (MacOS)
When executing "cordova run android", I got error message: "Error: spawn EACCES". By using --verbose:
When I checked the access permission of /Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle, I found that there is no execute permission. The solution for the error is just by modifying the access permission:
That's all :)
$ cordova run android --verbose ... Running command: "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle" -p /Users/myuserid/cordova/myApp/platforms/android wrapper -b /Users/myuserid/cordova/myApp/platforms/android/wrapper.gradle Error: spawn EACCES
When I checked the access permission of /Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle, I found that there is no execute permission. The solution for the error is just by modifying the access permission:
$ sudo chmod +x /Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle
That's all :)
Friday, August 18, 2017
Realtime depth estimation using monocular camera
Just for playing around, I did a small modification to the monodepth_simple.py from the github of CVPR 2017 paper "Unsupervised Monocular Depth Estimation with Left-Right Consistency" (original source code: https://github.com/mrharicot/monodepth), so that it takes input image directly from a camera. To retrieve images from the camera without losing much performance, I refer to the articles from here and here.
I used i7 6700K + Nvidia GTX 970 + Logicool webcam C910:
It appears that although the trained model was Kitti, which is quite different from the scene from my apartment window, it still worked to a certain extent. If you are interested, you can download the modification: monodepth_opencv3.py and a small utility for retrieving the image:util.py.
To run the modification, download the original code and the ready-to-use model by following the instruction from the original Author ( here ). Then copy monodepth_opencv3.py and util.py to the same folder as the monodepth_simple.py. Finally, execute:
Note that it requires Python 2.7, TensorFlow 1.x, OpenCV >= 2.4 (I used OpenCV 3.2), and of course, a camera.
That's all :) Updated 2022/2/9: I put the files monodepth_opencv3.py and util.py in https://github.com/chnd/monodepth. And beware, the codes tested using old version of libraries: Python 2.7., TensorFlow 1.x, OpenCV 3.2. That's all :)
I used i7 6700K + Nvidia GTX 970 + Logicool webcam C910:
It appears that although the trained model was Kitti, which is quite different from the scene from my apartment window, it still worked to a certain extent. If you are interested, you can download the modification: monodepth_opencv3.py and a small utility for retrieving the image:util.py.
To run the modification, download the original code and the ready-to-use model by following the instruction from the original Author ( here ). Then copy monodepth_opencv3.py and util.py to the same folder as the monodepth_simple.py. Finally, execute:
$ python ./monodepth_opencv3.py --checkpoint_path ./model/model_kitti
Note that it requires Python 2.7, TensorFlow 1.x, OpenCV >= 2.4 (I used OpenCV 3.2), and of course, a camera.
That's all :) Updated 2022/2/9: I put the files monodepth_opencv3.py and util.py in https://github.com/chnd/monodepth. And beware, the codes tested using old version of libraries: Python 2.7., TensorFlow 1.x, OpenCV 3.2. That's all :)
Labels:
OpenCV,
python,
tensorflow
Tuesday, August 15, 2017
TensorFlow: could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
When running the TensorFlow's object-detection model inference with my own dataset, I got the following error (with Nvidia GTX 970, CUDA 8, TensorFlow 1.2.1 through pip, and Ubuntu 16.04):
2017-08-15 21:18:06.254989: E tensorflow/stream_executor/cuda/cuda_dnn.cc:359] could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR 2017-08-15 21:18:06.255027: E tensorflow/stream_executor/cuda/cuda_dnn.cc:326] could not destroy cudnn handle: CUDNN_STATUS_BAD_PARAM 2017-08-15 21:18:06.255036: F tensorflow/core/kernels/conv_ops.cc:671] Check failed: stream->parent()->GetConvolveAlgorithms(&algorithms)Solution from https://github.com/tensorflow/tensorflow/issues/6698, by enabling the GPU's allow_growth flag, solved my problem:
config = tf.ConfigProto() config.gpu_options.allow_growth = True sess = tf.Session(config=config)That's all :)
Labels:
python,
tensorflow
Sunday, July 30, 2017
Installing Chrome on Ubuntu (16.04)
I recently installed Linux alongside Windows (dual boot). When I tried to install Chrome by downloading the latest installer from here, I got the following error:
$ sudo dpkg -i ./google-chrome-stable_current_amd64.deb
(Reading database ... 219479 files and directories currently installed.) Preparing to unpack .../google-chrome-stable_current_amd64.deb ... Unpacking google-chrome-stable (60.0.3112.78-1) over (60.0.3112.78-1) ... dpkg: dependency problems prevent configuration of google-chrome-stable: google-chrome-stable depends on libappindicator1; however: Package libappindicator1 is not installed. dpkg: error processing package google-chrome-stable (--install): dependency problems - leaving unconfigured Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ... Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ... Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ... Rebuilding /usr/share/applications/bamf-2.index... Processing triggers for mime-support (3.59ubuntu1) ... Processing triggers for man-db (2.7.5-1) ... Errors were encountered while processing: google-chrome-stableThanks to the blog post from here, the solution is straightforward. To satisfy the dependencies, execute the following command and re-execute the dpkg command shown above.
$ sudo apt-get -f installThat's all :)
Labels:
linux howto,
ubuntu
Monday, May 22, 2017
Tensorflow 1.1 (GPU) on Windows with cuDNN 6.0: No module named '_pywrap_tensorflow'
Short notes: if you got trouble importing tensorflow 1.1 (GPU) on Windows with cuDNN 6.0, try to use cuDNN 5.1 and ensure that the MSVC++2015 redistributable has been installed.
Reference: https://github.com/tensorflow/tensorflow/issues/7705
That's all :)
Reference: https://github.com/tensorflow/tensorflow/issues/7705
That's all :)
Labels:
python
Saturday, May 13, 2017
Update Anaconda Navigator 1.5.0
I had trouble updating Anaconda Navigator from 1.5.0 to 1.5.2 in Windows 10. While there was a message indicating that the update was successful, the version remains.
Gladly found the solution here: https://github.com/ContinuumIO/anaconda-issues/issues/1583 :
- Open command prompt
- Execute:
C:¥> conda update --all --prefix <path_to_the_installed_conda>
Labels:
python
Subscribe to:
Posts (Atom)