Skip to content
Snippets Groups Projects
Commit 46efed82 authored by 김주영's avatar 김주영
Browse files

test1

parent ef29f4c6
No related branches found
No related tags found
No related merge requests found
Pipeline #8540 failed
Showing
with 464 additions and 0 deletions
package com.example.myapplication;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class OverlaySurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder surfaceHolder ;
private Paint paint;
private List<Integer> pathColorList;
private Canvas canvas;
private List<DetectionObject> objects = new ArrayList<>();
public OverlaySurfaceView(SurfaceView surfaceView) {
super(surfaceView.getContext());
surfaceView.getHolder().addCallback(this);
surfaceView.setZOrderOnTop(true);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.setFormat(PixelFormat.TRANSPARENT);
paint = new Paint();
pathColorList = Arrays.asList(Color.RED, Color.GREEN, Color.CYAN, Color.BLUE);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// SurfaceView를 투명하게 만듭니다.
surfaceHolder.setFormat(PixelFormat.TRANSPARENT);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
public void draw(List<DetectionObject> detectedObjectList) {
// objects = detectedObjectList;
// Log.d("TAG", "draw: " + detectedObjectList.size());
// SurfaceHolder를 통해 캔버스를 가져옵니다.
// Log.d("TAG", "draw: " + detectedObjectList.size());
// for(int i = 0; i< detectedObjectList.size(); i++) {
// Log.d("TAG", "draw: " + detectedObjectList.get(i).getLabel());
// Log.d("TAG", "draw: " + detectedObjectList.get(i).getBoundingBox().toString());
// }
canvas = surfaceHolder.lockCanvas();
if (canvas == null) return;
Log.d("TAG", "draw: " + detectedObjectList.size());
// 이전에 그린 것을 지웁니다.
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
for (int i = 0; i < detectedObjectList.size(); i++) {
DetectionObject detectionObject = detectedObjectList.get(i);
// 바운딩 박스 그리기
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(7f);
paint.setAntiAlias(false);
RectF rectF = detectionObject.getBoundingBox();
canvas.drawRect(rectF.left,rectF.top,rectF.right, rectF.bottom,paint);
// canvas.drawRect(detectionObject.getBoundingBox(), paint);
// 라벨과 점수 표시
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setTextSize(77f);
canvas.drawText(
detectionObject.getLabel() + " " + String.format("%.2f%%", detectionObject.getScore() * 100),
detectionObject.getBoundingBox().left,
detectionObject.getBoundingBox().top - 5f,
paint
);
}
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
package com.example.myapplication;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.media.Image;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicYuvToRGB;
import android.renderscript.Type;
import java.nio.ByteBuffer;
public class YuvToRgbConverter {
private final RenderScript rs;
private final ScriptIntrinsicYuvToRGB scriptYuvToRgb;
private int pixelCount = -1;
private byte[] yuvBuffer;
private Allocation inputAllocation;
private Allocation outputAllocation;
public YuvToRgbConverter(Context context) {
rs = RenderScript.create(context);
scriptYuvToRgb = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
}
public synchronized void yuvToRgb(Image image, Bitmap output) {
if (!yuvBufferInitialized()) {
pixelCount = image.getCropRect().width() * image.getCropRect().height();
int pixelSizeBits = ImageFormat.getBitsPerPixel(ImageFormat.YUV_420_888);
yuvBuffer = new byte[pixelCount * pixelSizeBits / 8];
}
imageToByteArray(image, yuvBuffer);
if (!allocationsInitialized(output)) {
Type elemType = new Type.Builder(rs, Element.YUV(rs)).setYuvFormat(ImageFormat.NV21).create();
inputAllocation = Allocation.createSized(rs, elemType.getElement(), yuvBuffer.length);
outputAllocation = Allocation.createFromBitmap(rs, output);
}
inputAllocation.copyFrom(yuvBuffer);
scriptYuvToRgb.setInput(inputAllocation);
scriptYuvToRgb.forEach(outputAllocation);
outputAllocation.copyTo(output);
}
private boolean yuvBufferInitialized() {
return yuvBuffer != null;
}
private boolean allocationsInitialized(Bitmap output) {
return inputAllocation != null && outputAllocation != null && outputAllocation.getType().getX() == output.getWidth() && outputAllocation.getType().getY() == output.getHeight();
}
private void imageToByteArray(Image image, byte[] outputBuffer) {
assert image.getFormat() == ImageFormat.YUV_420_888;
Rect imageCrop = image.getCropRect();
Image.Plane[] imagePlanes = image.getPlanes();
for (int planeIndex = 0; planeIndex < imagePlanes.length; planeIndex++) {
int outputStride;
int outputOffset;
switch (planeIndex) {
case 0:
outputStride = 1;
outputOffset = 0;
break;
case 1:
outputStride = 2;
outputOffset = pixelCount + 1;
break;
case 2:
outputStride = 2;
outputOffset = pixelCount;
break;
default:
return;
}
Image.Plane plane = imagePlanes[planeIndex];
ByteBuffer planeBuffer = plane.getBuffer();
int rowStride = plane.getRowStride();
int pixelStride = plane.getPixelStride();
Rect planeCrop = (planeIndex == 0) ? imageCrop : new Rect(imageCrop.left / 2, imageCrop.top / 2, imageCrop.right / 2, imageCrop.bottom / 2);
int planeWidth = planeCrop.width();
int planeHeight = planeCrop.height();
byte[] rowBuffer = new byte[rowStride];
for (int row = 0; row < planeHeight; row++) {
planeBuffer.position((row + planeCrop.top) * rowStride + planeCrop.left * pixelStride);
if (pixelStride == 1 && outputStride == 1) {
planeBuffer.get(outputBuffer, outputOffset, planeWidth);
outputOffset += planeWidth;
} else {
planeBuffer.get(rowBuffer, 0, planeWidth);
for (int col = 0; col < planeWidth; col++) {
outputBuffer[outputOffset] = rowBuffer[col * pixelStride];
outputOffset += outputStride;
}
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.camera.view.PreviewView
android:id="@+id/cameraView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<SurfaceView
android:id="@+id/resultView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
MyApplication/app/src/main/res/mipmap-hdpi/ic_launcher.webp

1.37 KiB

MyApplication/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp

2.83 KiB

MyApplication/app/src/main/res/mipmap-mdpi/ic_launcher.webp

982 B

MyApplication/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp

1.73 KiB

MyApplication/app/src/main/res/mipmap-xhdpi/ic_launcher.webp

1.86 KiB

MyApplication/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp

3.83 KiB

MyApplication/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp

2.82 KiB

MyApplication/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp

5.78 KiB

MyApplication/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp

3.75 KiB

MyApplication/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp

7.6 KiB

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">My Application</string>
</resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment