posenet add front Camera

styletransfer demo no save result function
pull/10521/head
hukang hwx963878 4 years ago
parent ca7c945597
commit 0b68f4b247

@ -8,8 +8,8 @@ android {
applicationId "com.mindspore.himindspore"
minSdkVersion 21
targetSdkVersion 30
versionCode 4
versionName "1.1.2"
versionCode 5
versionName "1.1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {

@ -292,7 +292,7 @@ public class SplashActivity extends BaseActivity<MainPresenter> implements MainC
public void showUpdate(final UpdateInfoBean updateInfo) {
if (now_version == updateInfo.getVersionCode()) {
Toast.makeText(this, "已经是最新版本", Toast.LENGTH_SHORT).show();
// Toast.makeText(this, "已经是最新版本", Toast.LENGTH_SHORT).show();
Log.d(TAG + "版本号是", "onResponse: " + now_version);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);

@ -1,23 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mindspore.posenet;
import android.media.Image;
import android.view.SurfaceView;
public interface CameraDataDealListener {
void dataDeal(Image image, SurfaceView surfaceView);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -27,5 +27,14 @@
android:text="MindSpore PoseNet"
android:textColor="#ffffff"
android:textSize="20sp" />
<ImageView
android:onClick="onClickSwitch"
android:clickable="true"
android:layout_marginEnd="10dp"
android:layout_gravity="center_vertical|right"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/ic_camera_switch"/>
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>

@ -1,23 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mindspore.posenetdemo;
import android.media.Image;
import android.view.SurfaceView;
public interface CameraDataDealListener {
void dataDeal(Image image, SurfaceView surfaceView);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -19,7 +19,7 @@
android:background="#66000000">
<TextView
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/logo2"
android:drawablePadding="5dp"
@ -27,5 +27,14 @@
android:text="MindSpore PoseNet"
android:textColor="#ffffff"
android:textSize="20sp" />
<ImageView
android:onClick="onClickSwitch"
android:clickable="true"
android:layout_marginEnd="10dp"
android:layout_gravity="center_vertical|right"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/ic_camera_switch"/>
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mindspore.styletransferdemo">
<uses-permission android:name="android.permission.CAMERA" />
@ -34,6 +35,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.mindspore.styletransferdemo.fileprovider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/style_file_paths" />
</provider>
</application>
</manifest>

@ -89,7 +89,7 @@ public class BitmapUtils {
}
// Scale pictures to screen width.
private static Bitmap zoomImage(Bitmap imageBitmap, int targetWidth, int maxHeight) {
public static Bitmap zoomImage(Bitmap imageBitmap, int targetWidth, int maxHeight) {
float scaleFactor =
Math.max(
(float) imageBitmap.getWidth() / (float) targetWidth,
@ -104,6 +104,26 @@ public class BitmapUtils {
return resizedBitmap;
}
public static Bitmap changeBitmapSize(Bitmap bitmap, int targetWidth, int targetHeight) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Log.e("width", "width:" + width);
Log.e("height", "height:" + height);
float scaleWidth = ((float) targetWidth) / width;
float scaleHeight = ((float) targetHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
bitmap.getWidth();
bitmap.getHeight();
Log.e("newWidth", "newWidth" + bitmap.getWidth());
Log.e("newHeight", "newHeight" + bitmap.getHeight());
return bitmap;
}
/**
* Get the rotation angle of the photo.
*

@ -16,16 +16,24 @@
package com.mindspore.styletransferdemo;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.exifinterface.media.ExifInterface;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@ -33,6 +41,8 @@ import java.nio.ByteOrder;
public class ImageUtils {
private static final String TAG = "ImageUtils";
private static Matrix decodeExifOrientation(int orientation) {
Matrix matrix = new Matrix();
@ -198,4 +208,59 @@ public class ImageUtils {
}
return ret;
}
// Save the picture to the system album and refresh it.
public static void saveToAlbum(final Context context, Bitmap bitmap) {
File file = null;
String fileName = System.currentTimeMillis() + ".jpg";
File root = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), context.getPackageName());
File dir = new File(root, "image");
if (dir.mkdirs() || dir.isDirectory()) {
file = new File(dir, fileName);
}
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.flush();
} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage());
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} finally {
try {
if (os != null) {
os.close();
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
}
if (file == null) {
return;
}
// Gallery refresh.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String path = null;
try {
path = file.getCanonicalPath();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
MediaScannerConnection.scanFile(context, new String[]{path}, null,
new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(uri);
context.sendBroadcast(mediaScanIntent);
}
});
} else {
String relationDir = file.getParent();
File file1 = new File(relationDir);
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(file1.getAbsoluteFile())));
}
}
}

@ -0,0 +1,9 @@
package com.mindspore.styletransferdemo;
import android.view.View;
public interface OnBackgroundImageListener {
void onBackImageSelected(int position);
void onImageAdd(View view);
}

@ -1,92 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mindspore.styletransferdemo;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
* Use the {@link StyleFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class StyleFragment extends DialogFragment {
private OnListFragmentInteractionListener listener;
public StyleFragment() {
// Required empty public constructor
}
public static StyleFragment newInstance() {
StyleFragment fragment = new StyleFragment();
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_style, container, false);
List<String> styles = new ArrayList<>();
try {
styles.addAll(Arrays.asList(getActivity().getAssets().list("thumbnails")));
} catch (IOException e) {
e.printStackTrace();
}
if (view instanceof RecyclerView) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3);
((RecyclerView) view).setLayoutManager(gridLayoutManager);
((RecyclerView) view).setAdapter(new StyleRecyclerViewAdapter(getActivity(), styles, listener));
}
return view;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
this.listener = (StyleFragment.OnListFragmentInteractionListener) context;
}
}
public void onDetach() {
super.onDetach();
this.listener = null;
}
public interface OnListFragmentInteractionListener {
void onListFragmentInteraction(String item);
}
}

@ -16,7 +16,6 @@
package com.mindspore.styletransferdemo;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -27,35 +26,16 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.List;
public class StyleRecyclerViewAdapter extends RecyclerView.Adapter<StyleRecyclerViewAdapter.StyleItemViewHolder> {
private View.OnClickListener mOnClickListener;
private List<String> stylesList;
private Context context;
private StyleFragment.OnListFragmentInteractionListener mListener;
private final int[] IMAGES;
private final Context context;
private final OnBackgroundImageListener mListener;
public StyleRecyclerViewAdapter(Context context, List<String> stylesList, StyleFragment.OnListFragmentInteractionListener mListener) {
this.stylesList = stylesList;
public StyleRecyclerViewAdapter(Context context, int[] IMAGES, OnBackgroundImageListener mListener) {
this.IMAGES = IMAGES;
this.context = context;
this.mListener = mListener;
this.mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
}
};
this.mOnClickListener = (View.OnClickListener) (new View.OnClickListener() {
public final void onClick(View v) {
if (v.getTag() != null && v.getTag() instanceof String) {
mListener.onListFragmentInteraction(String.valueOf(v.getTag()));
}
}
});
}
@NonNull
@ -68,21 +48,27 @@ public class StyleRecyclerViewAdapter extends RecyclerView.Adapter<StyleRecycler
@Override
public void onBindViewHolder(@NonNull StyleItemViewHolder holder, int position) {
String imagePath = stylesList.get(position);
Glide.with(context).
load(Uri.parse("file:///android_asset/thumbnails/" + imagePath)).
centerInside().
load(IMAGES[position]).
into(holder.getImageView());
View view = holder.getMView();
view.setTag(imagePath);
view.setOnClickListener(this.mOnClickListener);
view.setTag(IMAGES[position]);
view.setOnClickListener(view1 -> {
if (mListener != null) {
if (IMAGES.length - 1 == position) {
mListener.onImageAdd(holder.getImageView());
} else {
mListener.onBackImageSelected(position);
}
}
});
}
@Override
public int getItemCount() {
return stylesList == null ? 0 : stylesList.size();
return IMAGES == null ? 0 : IMAGES.length;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save