Exemple #1
0
void consumer(void)
{
    int value;
    while (!done) {
        while (spsc_queue.pop(value))
            ++consumer_count;
    }

    while (spsc_queue.pop(value))
        ++consumer_count;
}
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  consumer
 *  Description:  处理图像线程,计算hog和显示
 * =====================================================================================
 */
void consumer(void)
{
	
	while (true){
		vector<Rect> found, found_filtered;
		spsc_queue.pop(showimg);
		hog.detectMultiScale(showimg, found, 0, Size(4,4), Size(0,0), 1.05, 2);
		for (i=0; i<found.size(); i++)
		{
			Rect r = found[i];
			for (j=0; j<found.size(); j++)
				if (j!=i && (r & found[j])==r)
					break;
			if (j==found.size())
				found_filtered.push_back(r);
		}
		for (i=0; i<found_filtered.size(); i++)
		{
			Rect r = found_filtered[i];
			r.x += cvRound(r.width*0.1);
			r.width = cvRound(r.width*0.8);
			r.y += cvRound(r.height*0.06);
			r.height = cvRound(r.height*0.9);
			rectangle(showimg, r.tl(), r.br(), cv::Scalar(0,255,0), 1);
		}
		imshow("1",showimg);
		waitKey(5);
	}

}
int main(int argc, char** argv)
{
        cout << "boost::lockfree::queue is ";
	if (!spsc_queue.is_lock_free())
		cout << "not ";
	cout << "lockfree" << endl;
	vector<float> detector = load_lear_model(argv[1]); /* load model */
	hog.setSVMDetector(detector);

	cap.open("d://1.avi");
	//cap.open("http://10.104.5.192:8888/?action=stream?dummy=param.mjpg");//get image by mjpeg stream
	cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
	cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
	if (!cap.isOpened())
		return -1;

	thread mThread( producer );
	Sleep(5000);                                /* 让生产者先生产一会儿 */

	thread mThread2( consumer );
	mThread.join();
	mThread2.join();

	return 0;
}
Exemple #4
0
void producer(void)
{
    for (int i = 0; i != iterations; ++i) {
        int value = ++producer_count;
        while (!spsc_queue.push(value))
            ;
    }
}
Exemple #5
0
void randn(float *array, int n)
{
    int consumed, consumer_count;
    consumer_count = 0;
    while (consumer_count < n)
        while ( consumed = spsc_queue.pop(&array[consumer_count], n-consumer_count) )
            consumer_count = consumer_count + consumed;
}
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  producer
 *  Description:  简单的获取图像
 * =====================================================================================
 */
void producer(void)
{
	while (true)
	{
		cap.read(img);                          /* 获取图像 */
		spsc_queue.push(img);                   /* 加入到缓存队列中 */

	}
}
Exemple #7
0
int main(int argc, char* argv[])
{
    using namespace std;
    cout << "boost::lockfree::queue is ";
    if (!spsc_queue.is_lock_free())
        cout << "not ";
    cout << "lockfree" << endl;

    boost::thread producer_thread(producer);
    boost::thread consumer_thread(consumer);

    producer_thread.join();
    done = true;
    consumer_thread.join();

    cout << "produced " << producer_count << " objects." << endl;
    cout << "consumed " << consumer_count << " objects." << endl;
}
Exemple #8
0
void rng_producer(void)
{
    float *arr = new float[RNG_ARRAY_SIZE];
    int produced, producer_count;

	while (!rng_producer_done)
	{
        producer_count = 0;

        /* Generate n floats on device */
        curandGenerateNormal(gen, devData, RNG_ARRAY_SIZE, 0.0, 1.0);
        /* Copy device memory to host */
        cudaMemcpy(arr, devData, RNG_ARRAY_SIZE * sizeof(float), cudaMemcpyDeviceToHost);
        
        while (producer_count < RNG_ARRAY_SIZE && !rng_producer_done)
            while ( produced = spsc_queue.push(&arr[producer_count], RNG_ARRAY_SIZE -producer_count) )
                producer_count = producer_count + produced; 
	}
    delete(arr);
}
	inline bool Queue(ISqlStmt_t query)
	{
		return m_Queue.push(query) && ++m_UnprocessedQueries;
	}
	inline void Call(Callback_t callback)
	{
		m_Queue.push(callback);
	}