【问题标题】:Recognizing when the user is driving, walking, biking识别用户何时开车、步行、骑自行车
【发布时间】:2015-07-25 07:34:54
【问题描述】:

我试图找到最可靠的方法来识别用户是在开车、步行、骑自行车还是静止不动。我将在 Android 应用程序中使用它。我希望尽可能避免使用 GPS。

请告诉我哪些算法适合您,它们的优点和缺点。谢谢!

【问题讨论】:

  • 我的第一个想法是为每种运输方式设置速度阈值和设备检测到的一定数量的“摇晃”。但是您可能必须使用 GPS 来识别用户的速度。

标签: java android ios machine-learning artificial-intelligence


【解决方案1】:

Google 在 Google Play 服务中为此提供了一个 API。查看https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html

我不建议您自己编写代码,这并不容易(我比 Google 早一年就有了一个版本,它有问题而且很耗电)。

【讨论】:

  • 感谢您的回复!我试过了,但准确度不是很好。置信度指标通常太低而无法依赖。
  • 信心低,因为这不是一个简单的问题。如果他们以每小时 10 英里的速度行驶,是骑自行车,还是在停车场缓慢行驶?如果他们停下来 30 秒,他们是完成驾驶还是闯红灯? 60秒呢? 120?它的所有猜测工作真的。如果你在这里问,而不是实施你自己的绝妙想法,你真的认为你会比他们在一个团队和花费大量时间的情况下做得更好吗?
【解决方案2】:

您可能永远不会得到完全准确的结果,但可以使用以下方法确定合理的估计值

- GPS to identify speed
- Is the charger plugged in
- is the phone off, or on screensaver
- is the movement detector going off a lot - likely walking but may be driving on dirt road

我正在玩这个的简单版本如下(抱歉代码是在 Python 中)

def inspect_phone(self):
    self.phone_gps_lat = 137.0000  # get from phone
    self.phone_gps_lng = 100.0000  # get from phone
    self.phone_moving = False      #  get from phone
    self.phone_move_dist_2_mn = 4
    self.phone_on_charge = True
    self.screen_saver = False
    #-------------------------------
    phone_status = ''
    if self.phone_on_charge == True:
        phone_status += 'Phone is charging'
        if self.phone_moving == True:
            phone_status += ', driving in Car'
        else:
            phone_status += ', sitting still'
    else:
        if self.screen_saver == False:
            phone_status += 'Phone is being used'
        else:
            phone_status += 'Phone is off'
        if self.phone_moving == True:
            if self.phone_move_dist_2_mn < 5:
                phone_status += ', going for Walk'
            elif  self.phone_move_dist_2_mn > 500:
                phone_status += ', flying on Plane'
            else:    
                phone_status += ', riding on ' + transport['Public']
    return phone_status

【讨论】:

    【解决方案3】:

    我做了一个小逻辑来为每个活动获取最佳折线并优化绘制,因为我们需要一定数量的纬度和经度才能绘制出用户制作的最佳轨迹。

    假设当用户按下开始一个新活动时,它会提示 3 个选项,跑步、步行或骑自行车。

    此方法获取用户选择的内容,并为每个更新 locationRequest。

     public void setTrackActivity(long interval, long fastInterval) {
    
                //Update the locationRequest intervals for each different Activity
                mLocationRequest.setInterval(interval);
                mLocationRequest.setFastestInterval(fastInterval);
                mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    
        }
    
    • 对于步行,我将 locationRequest 间隔设置在 6 秒内 每个请求的延迟。
    • 为了运行,我将 locationRequest 间隔设置在 2 秒延迟内 每个请求。
    • 为了运行,我将 locationRequest 间隔设置在 1 秒延迟内 每个请求。

    然后,为了在绘制地图时节省更多的折线,我采用了相同的概念。如果用户正在走路,它会在每 30 条折线中追踪一条折线

     public void drawTrack(GoogleMap googleMap) {
    
            googleMap.clear();  //Clearing markers and polylines
    
            PolylineOptions polyline_options = new PolylineOptions().addAll(mLinkedList)
                    .color(ContextCompat.getColor(mContext, R.color.colorAccent)).width(Constants.POLYLINE_WIDTH).geodesic(true);
    
            // Adding the polyline to the map
            Polyline polyline = googleMap.addPolyline(polyline_options);
            // set the zindex so that the poly line stays on top of my tile overlays
            polyline.setZIndex(1000);
            // we add each polyline to an array of polylines
            mPolylinesArray.add(polyline);
            // We add the latest latlang points we got
            mLatLngArray.add(mLinkedList.getLast());
    
            //If we have made 30 polylines we store 1 line starting from that first point to the last, so we can save 28 polylines and draw one instead of having so many points for lets say 10 meters, this value must change depending on the activity, if biking, runing or walking
            if (mLatLngArray.size() % 30 == 0) {
                // First we delete all polylines saved at the array
                for (Polyline pline : mPolylinesArray) {
                    pline.remove();
                }
                // We create a new polyline based on the first and last latlang from the 30 we took
                Polyline routeSoFar = googleMap.addPolyline(new PolylineOptions().color(Color.GREEN).width(Constants.POLYLINE_WIDTH).geodesic(true));
                // Draw the polyline
                routeSoFar.setPoints(mLatLngArray);
                // set the zindex so that the poly line stays on top of my tile overlays
                routeSoFar.setZIndex(1000);
                // Clear polyline array
                mPolylinesArray.clear();
                // Add polyline to array
                mPolylinesArray.add(routeSoFar);
            }
    
    }
    

    其中mLinkedListLinkedList&lt;LatLng&gt;,因此我们可以拥有第一个和最后一个元素(如果您想在活动开始和活动结束时绘制自定义标记)

    mPolylinesArrayPolylines ArrayList&lt;Polyline&gt; 的数组

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 2020-06-02
      • 2019-01-05
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2021-11-10
      相关资源
      最近更新 更多