Hi Guys , Welcome to proto coders point, In this python tutorial we will implement invisible cloak from harry potter using python opencv library.
what are python libraries to use invisible cloak?
What is numpy?
This is python libraries where we are using for arrays perpose in our project.
what is opencv?
In this library we are using opencv to capture the video.
What is Time?
so we are using time to capture the video in that time.
Step 1 :Create new python project
First we have to create a new python project to work on this invisible cloak.
File > New Project
Step 2 :Create a new python file to handle invisible cloak harry poter.
You need to create a new python file where you can write python code.
Right click on Project > New > Python File
i have created a new python file with name as ” invisibility cloak” using pycharm IDE.
Step 3 : Add library in your python project.
How to install the numpy , opencv-python , time module ?
File > Setting > Project Interpretor > Click on ” + ” > Search for “numpy,python-opencv” then select the package and then click on install package button.
As we have installed the numpy ,opencv-python model in our project now you can just import the which ever library we have installed then we write the farther code.then we have to capturing the video.after capturing video we have to give the camera to warm up.
Capturing the background in range of 60 .you should have video that have some seconds to dedicated to background farm so that it cloud easily save the background image.
Then we are reading from video.so we are convert the image -BGR to HSV as we focused on detection of red color. and then converting BGR to HSV for better detection or you can convert it to gray.
we have ranges should be carefully chosen the setting the lower and upper range for mask1.some setting the lower and upper range for mask2.then it replaced with some other code depending upon the color of your cloth.then refining the mask corresponding to the detected red color.then we are generating the final output
Hi Guys, Welcome to Proto Coders Point, In this android tutorial we will fetch data from our database (phpmyadmin) and store data in CSV file in android studio.
In other words we will learn store all the data recieved from server in to .csv file.
Final Output
So let’s begin.
My Database structure
This is my database with student table with some data in it
student table have data such as:
id
Firstname
Lastname
Phone
Creating of database and table in your phpmyadmin
just open phpmyadmin dashboard
Here create a new database named: mydatabase then in SQL tab query box copy paste below sql command/query, this command will create a new table by name “student”
Query:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
-- Database: `mydatabase`
--
-- Table structure for table `student`
--
CREATE TABLE `student` (
`id` int(11) NOT NULL,
`firstname` varchar(20) NOT NULL,
`lastname` varchar(20) NOT NULL,
`phone` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `student` (`id`, `firstname`, `lastname`, `phone`) VALUES
(1, 'Rajat', 'Palankar', '875899XXX11'),
(2, 'Pavan', 'Raikar', '9585XXX454'),
(3, 'Suraj', 'Somnache', '875899XXX22'),
(4, 'Manoj', 'Raikar', '8758XX8754'),
(5, 'sahil', 'pinjar', '75848XX555');
ALTER TABLE `student`
ADD PRIMARY KEY (`id`);
ALTER TABLE `student`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
This connect.php code will help use in getting connected with our database server.
fetch_all_data.php
<?php
include 'connect.php';
$query="select * from student";
$result=mysqli_query($conn,$query) or die('ERROR IN SELETION '.mysql_error());
$list="";
while($row=mysqli_fetch_array($result))
{
if($list=="")
$list=$row['id']."#".$row['firstname']."#".$row['lastname']."#".$row['phone'];
else
$list.="@".$row['id']."#".$row['firstname']."#".$row['lastname']."#".$row['phone'];
}
if($list=="")
echo "NONE";
else
echo $list;
?>
In above php code we are fetching all the data present in student table by using select * from student; sql command.
The above code will return data in a form of list.
each users data is been seperated using # and @. so that we can split using those symbols.
The above code response is as below:
Here @ symbol is been used to identify or split the data for individual student data.
Now, we are done with Server Side coding, let’s go to Android Studio
Android Studio Coding java
We are making use of StringBuilder that will hold all the data received from the php code(as above)
Snippit code
StringBuilder data =new StringBuilder();
data.append("id,firstname,lastname,phone"); // table row
data.append("\n"+ each_user[0]+","+ each_user[1]+","+ each_user[2]+","+ each_user[3]); // add data received from server
The data we received from our server we gonna store it in csv format and then we need to store it in our local storage location to do so we need to add ANDROID WRITE PERMISSION
Note that Andorid 7.0 Nouget (API Level 24) There is not support for unauthorized URL Request or response, So we need to provide the application with the server IP that we gonna use to fetch data from.
to do so you need to create a network_configuration.xml file in xml folder that you have created in step 2
right click on xml folder > new > xml resource file
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">35.232.167.171</domain> // replace with your IP address or website domain name
</domain-config>
</network-security-config>
Then add this file in android_manifest.xml file in <application tag
In xml file we just have a single view that is a BUTTON which on Click will fetch data from our php code and store the data in CSV file on your android phone local device.
Step 5: Android java code, to fetch data and store in csv file
This is the complete java code that you just need to add in MainActivity.java file
Code Explanation is given in below code as a Comment
package com.example.dataintocsvformat;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
Button download ;
ProgressDialog pdDialog;
private static final int PERMISSION_REQUEST_CODE = 100;
//php code URL path
String URL = "http://35.232.167.171/fetch_all_data.php";
StringBuilder data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
download=(Button)findViewById(R.id.download);
pdDialog = new ProgressDialog(MainActivity.this);
pdDialog.setMessage("Fetching Date...");
pdDialog.setCancelable(false);
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// to store csv file we need to write storage permission
// here we are checking is write permission is granted or no
if(checkPermission())
{
FetchData(URL);
}else{
// If permission is not granted we will request for the Permission
requestPermission();
}
}
});
}
// fetch data from server
private void FetchData(String url)
{
pdDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//we get the successful in String response
Log.e("MY_DATA",response);
try{
pdDialog.dismiss();
if(response.equals("NONE"))
{
Toast.makeText(MainActivity.this,"NO Data Found",Toast.LENGTH_LONG).show();
pdDialog.dismiss();
}else{
pdDialog.dismiss();
// In String response we get full data in a form of list
splitdata(response);
}
} catch (Exception e) {
e.printStackTrace();
pdDialog.dismiss();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pdDialog.dismiss();
}
})
{
@Override
protected Map<String, String> getParams() {
Map<String,String> params = new HashMap<>();
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
requestQueue.add(stringRequest);
}
private void splitdata(String response) {
System.out.println("GET DATA IS "+response);
// response will have a @ symbol so that we can split individual user data
String res_data[] = response.split("@");
//StringBuilder to store the data
data = new StringBuilder();
//row heading to store in CSV file
data.append("id,firstname,lastname,phone");
for(int i = 0; i<res_data.length;i++){
//then we split each user data using # symbol as we have in the response string
final String[] each_user =res_data[i].split("#");
System.out.println("Splited # ID: "+ each_user[0]);
System.out.println("Splited # Firstname? : "+ each_user[1]);
System.out.println("Splited # Lastname? : "+ each_user[2]);
System.out.println("Splited # Phone ? : "+ each_user[3]);
// then add each user data in data string builder
data.append("\n"+ each_user[0]+","+ each_user[1]+","+ each_user[2]+","+ each_user[3]);
}
CreateCSV(data);
}
private void CreateCSV(StringBuilder data) {
Calendar calendar = Calendar.getInstance();
long time= calendar.getTimeInMillis();
try {
//
FileOutputStream out = openFileOutput("CSV_Data_"+time+".csv", Context.MODE_PRIVATE);
//store the data in CSV file by passing String Builder data
out.write(data.toString().getBytes());
out.close();
Context context = getApplicationContext();
final File newFile = new File(Environment.getExternalStorageDirectory(),"SimpleCVS");
if(!newFile.exists())
{
newFile.mkdir();
}
File file = new File(context.getFilesDir(),"CSV_Data_"+time+".csv");
Uri path = FileProvider.getUriForFile(context,"com.example.dataintocsvformat",file);
//once the file is ready a share option will pop up using which you can share
// the same CSV from via Gmail or store in Google Drive
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/csv");
intent.putExtra(Intent.EXTRA_SUBJECT, "Data");
intent.putExtra(Intent.EXTRA_STREAM, path);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent,"Excel Data"));
} catch (Exception e) {
e.printStackTrace();
}
}
// checking permission To WRITE
private boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
// request permission for WRITE Access
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(MainActivity.this, "Write External Storage permission allows us to save files. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.e("value", "Permission Granted, Now you can use local drive .");
} else {
Log.e("value", "Permission Denied, You cannot use local drive .");
}
break;
}
}
}
In this Android Studio Tutorial on Proto Coders Point, we have learned how to fetch data from database using PHP code and then store the response data in .csv file format using android app.
Hi Guys, Welcome to Proto Coders Point, In this Tutorial, we will Install gcloud windows 10 (Google Cloud SDK windows) and set up Google Compute Engine VM Instance, and connect FileZilla to google cloud to transfer files to your Google Cloud System.
How to download Google Cloud SDK Installer?
There are many ways by which you can install gcloud SDK on your OS, The best and easy way to install it is by using gcloud SDK installer
Yes, After downloading Filezilla, just install it in your system by launching the setup and just hit next next, install.
Now FileZilla and Gcloud is Successfully installed in your system
Connect FileZilla to Google cloud
Step 1: Launch gcloud SDK shell
Launch gcloud sdk shell run as Adminstration
now run ‘gloud auth login’ as shown in above screenshot, this command will open your default browser or ask you permission to select a browser.
Note: Keep your Google account signed in so that process will be must faster.
Then it will ask you some permission to allow access to google cloud SDK.
Just hit that Allow button
Now you have Successfully connect command shell with google cloud.
Step 2 : Generate filezilla ppk file
Then, you need to generate .ppk file so that you can add it to SFTP in your filezilla settings to connect to gcloud system.
To generate .ppk file you need to run gcloud command of your Compute Engine VM Instance
to get that command go to your Google Cloud Console > open Compute Engine → VM instance → Select VM Instance and Copy gcloud command line under SSH.
NOTE: Below command is my gcloud computer engine number, so don’t run the below command as it is, to get your system command follow above steps properly.
Then Copy your system gcloud command and paste in your gcloud SDK shell.
This Command will generate .ppk file that need to add in filezilla SFTP settings.
Now we are done with generating google_compute_engine.ppk file now you need to add this file in your Filezilla SFTP settings.
go to Edit > setting and add the ppk file you have generated using gcloud command, as shown in below screenshot
Step 4 : Add your Google Site to FileZilla
Go to File > Site Manager and add new site
protocal : select SFTP
host : get the host ip address of you google cloud system in Compute Engine VM Instance. as shown below
username and password will be same as your google account first name For example : my name is Rajat Palankar so my username and passwork will be rajat.
and then just hit the connect button, now filezilla will get connected to your google cloud system.
Step 5 : Change Owner of /var/www/html ( Optional )
By Default, the permission of file path /var/www/html will be _rw_r__r__ and by this you can’t save or make changed or create a new file, to do so you need to change the Owner of that path. then now you can use Filezilla to transfer files
sudo chown username -R /var/www/html
Conclusion
In this Tutorial article we learned how to install gcloud in windows, how to generate .ppk file using gcloud command and then use that .ppk file to connect to google cloud compute engine VM Instance using FileZilla
Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we will Learn how to implement Google Authentication with your flutter Apps using Firebase Services.
What you’ll learn?
– Login with Google
– Firebase Configuration
– Fetching user’s profile
– Logout
DEMO
Flutter Firebase Google SignIn | Flutter Login with Google Firebase
First of all, OffCourse you need to create a Flutter project, I use Android Studio as my IDE to Create my Flutter application, Hope you guys have Create your project on your respective IDE’s
Now Go to Firebase console and Setup your project to make use of Google Sign In service of Fireabase
Step 2 : Create new Project and Add Project as Android
Then, In you firebase console you need to create a new Firebase project or Open any Existing project, you can create the project as shown in below screenshots.
Then you while get new window to add app like in android,iOS, unity and web app check out the below screenshot to add new app.
In this tutorial we will just add app for android platform
Step 3 : Add Firebase to your android Project
How to get Package name for Android Flutter?
How to Generate SHA-1 certificate for Firebase Console?
Step 4 : Download the Config file (google-services.json)
Then once you app the package name and SHA-1 cerficate in firebase project, it will give you a json file called google-services.json that you need to add flutter project in your android package section as show below.
Step 5 : Go to Authentication option and Enable Google SignIn providers
In the last step, go to authentiation section on the left side of your firebase console and you need to Enable Google SignIn Provider Option to be able to login in with Google Services using Firebase.
enable google sign in provider in firebase console
Ok then, Now we are done with Server side that is, connecting our flutter project to firebase console.
Now let’s come to Coding part
Flutter Firebase Google Sign In
Step 1 : Add GoogleSignIn dependencies
A Flutter google sign in plugin for Google Sign In. Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!
In your Flutter Project, open pubspec.yaml file and add the Google Sign In Dependencies in it.
then in your main dart class file you need to create a new Instance object and give it a scope of “Email”, by giving scope as “email” this will open only email signin method.
Step 4 : Login Method
Now you need to perform a login method by with one can click on a button that will call a _login() method and googlesignin.signIn() will run.
googleSignIn.signIn();
just you need to use this google instance object and call sign in method.
Complete Code is given below.
Step 5 : Logout Method
If user is been signed in and need to logout/signout you need to call a method by with user can be able to signout himself.
googleSignIn.signOut();
just you need to use this google instance object and call sign out method.
Hi Guys, Welcome to Proto Coders Point, In this Android Tutorial we will create an app that can support multiple languages, In other words, the user can select his desired language to change the whole app language in android.
This is a Simple Example of how to make an android multi language app with an example – locale in android.
DEMO
Video Tutorial on change whole app language android programmatically
Step 1 − Create a new Android Project in Android Studio
Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. ( Name it as Change App language)
Step 2 – Create a new strings.xml with locale
In the values directory, you need to create a separate string.xml(hi) or any other language
Here is how to create a locale in android string with a language
right-click on values directory => New => Values Resource File
The below dialog will pop up in the android studio
Here you need to select your locale languages that your app will support.
After creating saperate strings.xml files for particular languages your string directory will look something like this.
Now in those strings.xml file add the translated strings
string.xml (hi) for hindi language in your android app.
likewise you can add different language that you want to add into your android applicaton.
Step 3 – Create a LocaleHelper Class
Now create new java file and name it as Localehelper and add the below code
This class will help you in getting and storing language that a user has previously selected before he close the application, we will use SharedPreferences to store the locale selected by user in app.
Here in above code we have a RelativeLayout with OnClickEvent, Then user will click the RelativeLayout a AlertDialog will popup asking for language selection, by using which user can change language of his application.
For Example: When user select language as Hindi, The strings.xml (hi) will get loaded and all the text in the application will turn it language string that come from strings.xml (hi), likewise if user select kannada as his app language then strings gets loaded from strings.xml(kn).
and if he select language as English all language will come back to default string.xml
Conclusion
In this tutorial we learnt how to change whole app language in android programmatically using strings.xml locale.
Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we gonna design a Login and Registration UI Design by using “VELOCITY X” Flutter Library developed by Pawan Kumar using Flutter SDK.
What is Flutter Velocity X?
The Velocity X library in flutter development is a minimalist flutter framework that helps you in building custom Application design Rapidly.
Velocity X comes with various properties that we can apply to our flutter widget such as Color, Padding, Text , Box, Card, SizedBox and many more.