gpt4 book ai didi

android 触摸人体图像检测 body 部位。我应该使用什么布局元素?

转载 作者:行者123 更新时间:2023-11-29 15:08:29 24 4
gpt4 key购买 nike

在下图中,我想检测触摸事件发生在人体的哪个部位。我的想法是拥有一个 GridView 并确定发生触摸事件的人体位置。不过,GridView 似乎有点矫枉过正。使用不同的布局会是更好的方法吗?

 gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
BodyImage item = (BodyImage) parent.getItemAtPosition(position);
switch (position) {
case 0:

// code for head

break;
case 1:
// code for nose
case 2:
// code for n-human part

这是给观众一个想法的图片 enter image description here

最佳答案

首先感谢 Kris Larson 的上述回答。这个想法是叠加这里看到的两个图像 Images to be superposed in the Fragment并隐藏具有颜色的图像。右边的图像使用开源 Gimp 着色 GIMP

然后在 FrameLayout 上我动态添加了两个图像:

/**
* A Fragment that launches Draw
*/
public static class DrawSectionFragment extends Fragment {

public static final String ARG_SECTION_NUMBER = "section_number";
boolean touching = false;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
........

View rootView = inflater.inflate(R.layout.image_superposed, container, false);
// View rootView = inflater.inflate(R.layout.image_superposed, container);
final ImageView iv1 = (ImageView) rootView.findViewById(R.id.imgSecond);
iv1.setImageDrawable(getResources().getDrawable(R.drawable.twocolor1));
final Bitmap bitmap = ((BitmapDrawable)iv1.getDrawable()).getBitmap();

iv1.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
CxMediaPlayer mxMediaPlayer;
mxMediaPlayer = new CxMediaPlayer(getActivity().getBaseContext());
switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:
// TODO Auto-generated method stub
touching = true;
Matrix inverse = new Matrix();
iv1.getImageMatrix().invert(inverse);
float[] touchPoint = new float[]{event.getX(), event.getY()};
inverse.mapPoints(touchPoint);
int xCoord = Integer.valueOf((int) touchPoint[0]);
int yCoord = Integer.valueOf((int) touchPoint[1]);

int pixel = bitmap.getPixel(xCoord, yCoord);

int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);

if (pixel == Color.CYAN) {
//mxMediaPlayer = new CxMediaPlayer(getActivity().getBaseContext());
mxMediaPlayer.playShortResource(getActivity().getBaseContext(), 1) ;
}
if (pixel == Color.YELLOW) {

mxMediaPlayer.playShortResource(getActivity().getBaseContext(), 2) ;
}
if (pixel == Color.rgb(0,0,255)) {
CxMediaPlayer mxMediaPlayer1 = new CxMediaPlayer(getActivity().getBaseContext());
mxMediaPlayer1.playShortResource(getActivity().getBaseContext(), 2) ;
}

break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
touching = false;
//invalidate();
break;

}
// mxMediaPlayer.Release();
return true;
}
});;


return rootView;
}

关于android 触摸人体图像检测 body 部位。我应该使用什么布局元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34425904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com