MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / main

Function main

cpp_package/examples/ml/src/eeg_metrics.cpp:20–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20int main (int argc, char *argv[])
21{
22 BoardShim::enable_dev_board_logger ();
23
24 struct BrainFlowInputParams params;
25 int board_id = 0;
26 if (!parse_args (argc, argv, &params, &board_id))
27 {
28 return -1;
29 }
30 int res = 0;
31
32 BoardShim *board = new BoardShim (board_id, params);
33
34 try
35 {
36 board->prepare_session ();
37 board->start_stream ();
38
39#ifdef _WIN32
40 Sleep (5000);
41#else
42 sleep (5);
43#endif
44
45 board->stop_stream ();
46 BrainFlowArray<double, 2> data = board->get_board_data ();
47 board->release_session ();
48 std::cout << data << std::endl;
49 // calc band powers
50 int sampling_rate = BoardShim::get_sampling_rate ((int)BoardIds::SYNTHETIC_BOARD);
51 std::vector<int> eeg_channels = BoardShim::get_eeg_channels (board_id);
52 std::pair<double *, double *> bands =
53 DataFilter::get_avg_band_powers (data, eeg_channels, sampling_rate, true);
54
55 struct BrainFlowModelParams mindfulness_params (
56 (int)BrainFlowMetrics::MINDFULNESS, (int)BrainFlowClassifiers::DEFAULT_CLASSIFIER);
57 MLModel mindfulness_model (mindfulness_params);
58 mindfulness_model.prepare ();
59 std::cout << "Mindfulness :" << mindfulness_model.predict (bands.first, 5)[0] << std::endl;
60 mindfulness_model.release ();
61
62 struct BrainFlowModelParams restfulness_params (
63 (int)BrainFlowMetrics::RESTFULNESS, (int)BrainFlowClassifiers::DEFAULT_CLASSIFIER);
64 MLModel restfulness_model (restfulness_params);
65 restfulness_model.prepare ();
66 std::cout << "Restfulness :" << restfulness_model.predict (bands.first, 5)[0] << std::endl;
67 restfulness_model.release ();
68
69 delete[] bands.first;
70 delete[] bands.second;
71 }
72 catch (const BrainFlowException &err)
73 {
74 BoardShim::log_message ((int)LogLevels::LEVEL_ERROR, err.what ());
75 res = err.exit_code;
76 if (board->is_prepared ())
77 {

Callers

nothing calls this directly

Calls 15

enable_dev_board_loggerFunction · 0.85
get_sampling_rateFunction · 0.85
get_avg_band_powersFunction · 0.85
whatMethod · 0.80
parse_argsFunction · 0.70
prepare_sessionMethod · 0.65
start_streamMethod · 0.65
stop_streamMethod · 0.65
get_board_dataMethod · 0.65
release_sessionMethod · 0.65
prepareMethod · 0.65
predictMethod · 0.65

Tested by

no test coverage detected